diff options
author | brainopia <brainopia@evilmartians.com> | 2012-01-25 00:07:58 +0400 |
---|---|---|
committer | brainopia <brainopia@evilmartians.com> | 2012-01-25 23:04:40 +0400 |
commit | b258bec4317d1013ad4ce2659fa46c4b0bb43c96 (patch) | |
tree | 8d189bf4c6d1b3223d4cf82d35cbdb8427600fe8 /activesupport/lib | |
parent | 203771da9e0b0357f23e1c4e61d2e72578af4155 (diff) | |
download | rails-b258bec4317d1013ad4ce2659fa46c4b0bb43c96.tar.gz rails-b258bec4317d1013ad4ce2659fa46c4b0bb43c96.tar.bz2 rails-b258bec4317d1013ad4ce2659fa46c4b0bb43c96.zip |
Deprecate DateTime.local_offset
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/conversions.rb | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index e42453389e..6f730e4b6f 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -1,7 +1,11 @@ +require 'active_support/deprecation' + class DateTime class << self - # DateTimes aren't aware of DST rules, so use a consistent non-DST offset when creating a DateTime with an offset in the local zone + # *DEPRECATED*: Use +DateTime.civil_from_format+ directly. def local_offset + ActiveSupport::Deprecation.warn 'DateTime.local_offset is deprecated. ' \ + 'Use DateTime.civil_from_format directly.', caller ::Time.local(2012).utc_offset.to_r / 86400 end 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 e5f895478a..dc55e9c33c 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -64,8 +64,18 @@ class DateTime self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec, sec_fraction * 1000000) : self end + # Returns DateTime with local offset for given year if format is local else offset is zero + # + # DateTime.civil_from_format :local, 2012 + # # => Sun, 01 Jan 2012 00:00:00 +0300 + # DateTime.civil_from_format :local, 2012, 12, 17 + # # => Mon, 17 Dec 2012 00:00:00 +0000 def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0) - offset = utc_or_local.to_sym == :local ? local_offset : 0 + if utc_or_local.to_sym == :local + offset = ::Time.local(year, month, day).utc_offset.to_r / 86400 + else + offset = 0 + end civil(year, month, day, hour, min, sec, offset) end |