Module: Ocpp::Rails::TimestampParser
- Defined in:
- app/services/ocpp/rails/timestamp_parser.rb
Overview
Parses station-provided OCPP timestamps without hiding failures: a value that cannot be parsed falls back to server receive time, but the result is marked so the record can be flagged instead of silently entering the time series as fabricated data.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- SOURCE_STATION =
"station".freeze
- SOURCE_SERVER_FALLBACK =
"server_fallback".freeze
Class Method Summary collapse
Class Method Details
.parse(raw) ⇒ Object
17 18 19 20 21 22 |
# File 'app/services/ocpp/rails/timestamp_parser.rb', line 17 def self.parse(raw) Result.new(time: Time.parse(raw), source: SOURCE_STATION, raw: raw) rescue ArgumentError, TypeError ::Rails.logger.warn("[OCPP] Unparseable timestamp #{raw.inspect}; falling back to server time") Result.new(time: Time.current, source: SOURCE_SERVER_FALLBACK, raw: raw) end |