diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-11 13:57:05 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-11 13:57:05 +0000 |
commit | 48583f8bf74d1cefefea3cd6591bd546a9eaff6c (patch) | |
tree | 50ebc308bc70cddb151cf7ebdc375eaaae812fd1 /activesupport/lib/active_support | |
parent | 45a6f546b6047befdef9d4acb8fa6c18cc0dab09 (diff) | |
download | rails-48583f8bf74d1cefefea3cd6591bd546a9eaff6c.tar.gz rails-48583f8bf74d1cefefea3cd6591bd546a9eaff6c.tar.bz2 rails-48583f8bf74d1cefefea3cd6591bd546a9eaff6c.zip |
Deprecate obsolete Time to DateTime fallback methods
The Time.time_with_datetime_fallback, Time.utc_time and Time.local_time
methods were added to handle the limitations of Ruby's native Time
implementation. Those limitations no longer apply so we are deprecating
them in 4.0 and they will be removed in 4.1.
Diffstat (limited to 'activesupport/lib/active_support')
5 files changed, 14 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index d49d427d80..fe08ade7e0 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -75,7 +75,7 @@ class Date # # date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007 def to_time(form = :local) - ::Time.send("#{form}_time", year, month, day) + ::Time.send(form, year, month, day) end def xmlschema diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 9b9d83932e..9d3b81cf38 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -21,7 +21,7 @@ class String date_values[6] *= 1000000 offset = date_values.pop - ::Time.send("#{form}_time", *date_values) - offset + ::Time.send(form, *date_values) - offset end end diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 1f17378c8d..1f95f62229 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -3,6 +3,7 @@ require 'active_support/core_ext/time/conversions' require 'active_support/time_with_zone' require 'active_support/core_ext/time/zones' require 'active_support/core_ext/date_and_time/calculations' +require 'active_support/deprecation' class Time include DateAndTime::Calculations @@ -25,10 +26,13 @@ class Time end end + # *DEPRECATED*: Use +Time#utc+ or +Time#local+ instead. + # # Returns a new Time if requested year can be accommodated by Ruby's Time class # (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture); # otherwise returns a DateTime. def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0) + ActiveSupport::Deprecation.warn 'time_with_datetime_fallback is deprecated. Use Time#utc or Time#local instead', caller time = ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec) # This check is needed because Time.utc(y) returns a time object in the 2000s for 0 <= y <= 138. @@ -41,13 +45,19 @@ class Time ::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec) end + # *DEPRECATED*: Use +Time#utc+ instead. + # # Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:utc</tt>. def utc_time(*args) + ActiveSupport::Deprecation.warn 'utc_time is deprecated. Use Time#utc instead', caller time_with_datetime_fallback(:utc, *args) end + # *DEPRECATED*: Use +Time#local+ instead. + # # Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:local</tt>. def local_time(*args) + ActiveSupport::Deprecation.warn 'local_time is deprecated. Use Time#local instead', caller time_with_datetime_fallback(:local, *args) end diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index b931de3fac..0dbc198ea2 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -344,7 +344,7 @@ module ActiveSupport end def transfer_time_values_to_utc_constructor(time) - ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:nsec) ? Rational(time.nsec, 1000) : 0) + ::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec, Rational(time.nsec, 1000)) end def duration_of_variable_length?(obj) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index d087955587..c5fbddcb5f 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -252,7 +252,7 @@ module ActiveSupport # Time.zone = 'Hawaii' # => "Hawaii" # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00 def local(*args) - time = Time.utc_time(*args) + time = Time.utc(*args) ActiveSupport::TimeWithZone.new(nil, self, time) end |