Method: TZInfo::TimeOrDateTime#initialize
- Defined in:
- lib/tzinfo/time_or_datetime.rb
#initialize(timeOrDateTime) ⇒ TimeOrDateTime
Constructs a new TimeOrDateTime. timeOrDateTime can be a Time, DateTime or Integer. If using a Time or DateTime, any time zone information is ignored.
Integer timestamps must be within the range supported by Time on the platform being used.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tzinfo/time_or_datetime.rb', line 17 def initialize(timeOrDateTime) @time = nil @datetime = nil @timestamp = nil if timeOrDateTime.is_a?(Time) @time = timeOrDateTime # Avoid using the slower Rational class unless necessary. nsec = RubyCoreSupport.time_nsec(@time) usec = nsec % 1000 == 0 ? nsec / 1000 : Rational(nsec, 1000) @time = Time.utc(@time.year, @time.mon, @time.mday, @time.hour, @time.min, @time.sec, usec) unless @time.utc? @orig = @time elsif timeOrDateTime.is_a?(DateTime) @datetime = timeOrDateTime @datetime = @datetime.new_offset(0) unless @datetime.offset == 0 @orig = @datetime else @timestamp = timeOrDateTime.to_i if !RubyCoreSupport.time_supports_64bit && (@timestamp > 2147483647 || @timestamp < -2147483648 || (@timestamp < 0 && !RubyCoreSupport.time_supports_negative)) raise RangeError, 'Timestamp is outside the supported range of Time on this platform' end @orig = @timestamp end end |