Method: TZInfo::TimeOrDateTime#to_datetime

Defined in:
lib/tzinfo/time_or_datetime.rb

#to_datetimeObject

Returns the time as a DateTime.

When converting from a Time, the result is truncated to microsecond precision.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tzinfo/time_or_datetime.rb', line 71

def to_datetime
  # Thread-safety: It is possible that the value of @datetime may be 
  # calculated multiple times in concurrently executing threads. It is not 
  # worth the overhead of locking to ensure that @datetime is only 
  # calculated once.

  unless @datetime
    # Avoid using Rational unless necessary.
    u = usec
    s = u == 0 ? sec : Rational(sec * 1000000 + u, 1000000)
    @datetime = RubyCoreSupport.datetime_new(year, mon, mday, hour, min, s)
  end
  
  @datetime
end