Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/feedjira/core_ext/time.rb
Class Method Summary collapse
-
.parse_safely(dt) ⇒ Object
Parse a time string and convert it to UTC without raising errors.
Class Method Details
.parse_safely(dt) ⇒ Object
Parse a time string and convert it to UTC without raising errors. Parses a flattened 14-digit time (YYYYmmddHHMMMSS) as UTC.
Parameters
- dt<String or Time>
-
Time definition to be parsed.
Returns
A Time instance in UTC or nil if there were errors while parsing.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/feedjira/core_ext/time.rb', line 13 def self.parse_safely(dt) if dt case when dt.is_a?(Time) dt.utc when dt.respond_to?(:empty?) && dt.empty? nil when dt.respond_to?(:to_datetime) dt.to_datetime.utc when dt.to_s =~ /\A\d{14}\z/ parse("#{dt.to_s}Z", true) else parse(dt.to_s, true).utc end end rescue StandardError nil end |