From c685d12c19f953768ee445ab29faeb4a1be54535 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 1 Jul 2012 08:02:41 +0100 Subject: 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. --- .../lib/active_support/core_ext/date_time/conversions.rb | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index b6a3c02dd6..262c03540b 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -4,10 +4,6 @@ require 'active_support/core_ext/date_time/calculations' 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 to_s. @@ -57,16 +53,6 @@ class DateTime 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 -- cgit v1.2.3