lib/wukong/extensions/date_time.rb in wukong-1.4.11 vs lib/wukong/extensions/date_time.rb in wukong-1.4.12

- old
+ new

@@ -1,22 +1,24 @@ require 'time' +require 'date' DateTime.class_eval do # # Parses the time but never fails. # Return value is always in the UTC time zone. # - # A flattened time -- a 12-digit YYYYmmddHHMMMSS -- is treated as a UTC - # datetime. + # A flattened datetime -- a 12-digit YYYYmmddHHMMMSS -- is fixed to the UTC + # time zone by parsing it as YYYYmmddHHMMMSSZ <- 'Z' at end # def self.parse_safely dt + return nil if dt.blank? begin if dt.to_s =~ /\A\d{12}Z?\z/ - parse(dt+'Z', true).utc + parse(dt+'Z', true) else parse(dt, true).utc end - rescue StandardError - nil + rescue StandardError => e + Log.info e end end def self.parse_and_flatten str parse_safely(str).to_flat