Module: Finlight::FlexTime
- Defined in:
- lib/finlight/flex_time.rb
Overview
Parses the timestamp formats used by the finlight API: RFC 3339 with or without zone, space-separated, and date-only. Zone-less timestamps are interpreted as UTC, matching the sibling clients.
Class Method Summary collapse
-
.parse(value) ⇒ Time?
The parsed time in UTC, or nil for nil input.
Class Method Details
.parse(value) ⇒ Time?
Returns the parsed time in UTC, or nil for nil input.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/finlight/flex_time.rb', line 15 def parse(value) return nil if value.nil? return value.utc if value.is_a?(Time) s = value.to_s.strip iso_like = s.include?(" ") ? s.sub(" ", "T") : s DateTime.iso8601(iso_like).to_time.utc rescue ArgumentError, TypeError raise Error, "finlight: cannot parse timestamp: #{value.inspect}" end |