提交 c685d12c 编写于 作者: A Andrew White

Remove DateTime#to_time override

Currently if the offset is not zero then to_time returns self which
can lead to errors where a developer assumes that the value is a
Time. To solve this we can use the native implementation of
DateTime#to_time in Ruby 1.9.3 as it handles offsets properly and
is faster than our override.
上级 210cd756
......@@ -4,10 +4,6 @@
require 'active_support/values/time_zone'
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
# Convert to a formatted string. See Time::DATE_FORMATS for predefined formats.
#
# This method is aliased to <tt>to_s</tt>.
......@@ -57,16 +53,6 @@ def readable_inspect
alias_method :default_inspect, :inspect
alias_method :inspect, :readable_inspect
# 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
if offset == 0
::Time.utc_time(year, month, day, hour, min, sec, sec_fraction * 1000000)
else
self
end
end
# Returns DateTime with local offset for given year if format is local else offset is zero
#
# DateTime.civil_from_format :local, 2012
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册