Class: Time

Inherits:
Object show all
Defined in:
lib/nose/util.rb

Overview

Extend Time to allow conversion to DateTime instances

Instance Method Summary collapse

Instance Method Details

#to_datetimeDateTime

Convert to a DateTime instance stackoverflow.com/a/279785/123695

Returns:

  • (DateTime)


323
324
325
326
327
328
329
330
331
# File 'lib/nose/util.rb', line 323

def to_datetime
  # Convert seconds + microseconds into a fractional number of seconds
  seconds = sec + Rational(usec, 10**6)

  # Convert a UTC offset measured in minutes to one measured in a
  # fraction of a day.
  offset = Rational(utc_offset, 60 * 60 * 24)
  DateTime.new(year, month, day, hour, min, seconds, offset)
end