Sha256: 9c79bb3622585be69dc0acf687e174f11503081e98098cf0c85a738b79c52163

Contents?: true

Size: 635 Bytes

Versions: 6

Compression:

Stored size: 635 Bytes

Contents

class Time
  #
  # Parses the time but never fails.
  # Return value is always in the UTC time zone.
  #
  # A flattened datetime -- a 14-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
      case
      when dt.is_a?(Time)               then dt.utc
      when (dt.to_s =~ /\A\d{14}\z/)    then parse(dt.to_s+'Z', true)
      else                                   parse(dt.to_s,     true).utc
      end
    rescue StandardError => e
      Log.debug e
    end
  end unless method_defined?(:parse_safely)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gorillib-0.0.7 lib/gorillib/datetime/parse.rb
gorillib-0.0.6 lib/gorillib/datetime/parse.rb
gorillib-0.0.5 lib/gorillib/datetime/parse.rb
gorillib-0.0.4 lib/gorillib/datetime/parse.rb
gorillib-0.0.3 lib/gorillib/datetime/parse.rb
gorillib-0.0.2 lib/gorillib/datetime/parse.rb