Sha256: c45e57f7e40c78adb7783614c8ae704bde58af3fc051a9486c961e4dc03c96dc

Contents?: true

Size: 661 Bytes

Versions: 1

Compression:

Stored size: 661 Bytes

Contents

require 'date'

class DateTime
  # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
  # DateTimes outside the range of what can be created with Time.
  # remove_method :to_time if instance_methods.include?(:to_time)

  # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class.
  # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time.
  def to_time
    self.offset == 0 ? ::Time.utc(year, month, day, hour, min, sec, sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000)) : self
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whois-2.2.0 lib/core_ext/date_time/conversions.rb