Sha256: 9dc04009a331ade378df8fd87279b44577c2b24aa8f03f4c38422104b60c8668

Contents?: true

Size: 429 Bytes

Versions: 10

Compression:

Stored size: 429 Bytes

Contents

require 'time'
DateTime.class_eval do
  #
  # Parses the time but never fails.
  #
  # A flattened time -- a 12-digit YYYYmmddHHMMMSS -- is treated as a UTC
  # datetime.
  #
  def self.parse_safely dt
    begin
      if dt.to_s =~ /\A\d{12}Z?\z/
        parse(dt+'Z', true)
      else
        parse(dt, true)
      end
    rescue
      nil
    end
  end

  def self.parse_and_flatten str
    parse_safely(str).to_flat
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mrflip-wukong-0.1.0 lib/wukong/extensions/date_time.rb
wukong-1.4.9 lib/wukong/extensions/date_time.rb
wukong-1.4.7 lib/wukong/extensions/date_time.rb
wukong-1.4.6 lib/wukong/extensions/date_time.rb
wukong-1.4.5 lib/wukong/extensions/date_time.rb
wukong-1.4.2 lib/wukong/extensions/date_time.rb
wukong-1.4.1 lib/wukong/extensions/date_time.rb
wukong-1.4.0 lib/wukong/extensions/date_time.rb
wukong-0.1.4 lib/wukong/extensions/date_time.rb
wukong-0.1.1 lib/wukong/extensions/date_time.rb