Sha256: a2e865a160dc5081af2329c594bbcb38284f3015328d0c15046c41c2d2271534

Contents?: true

Size: 694 Bytes

Versions: 10

Compression:

Stored size: 694 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 unless method_defined?(:to_time)

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
whois-2.7.0 lib/whois/core_ext/date_time/conversions.rb
whois-2.6.4 lib/whois/core_ext/date_time/conversions.rb
whois-2.6.3 lib/whois/core_ext/date_time/conversions.rb
whois-2.6.2 lib/whois/core_ext/date_time/conversions.rb
whois-2.6.1 lib/whois/core_ext/date_time/conversions.rb
whois-2.6.0 lib/whois/core_ext/date_time/conversions.rb
whois-2.5.1 lib/whois/core_ext/date_time/conversions.rb
whois-2.5.0 lib/whois/core_ext/date_time/conversions.rb
whois-2.4.0 lib/whois/core_ext/date_time/conversions.rb
whois-2.3.0 lib/core_ext/date_time/conversions.rb