diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-03-11 04:26:20 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-03-11 04:26:20 +0000 |
commit | 52b57c662c129d72d44fa1ab9920a752c1973482 (patch) | |
tree | 90e89994fc4486e5523fe45df46f5d013e184a83 /activesupport/lib | |
parent | 3d2177df26c8934320277a7aed84595decd94662 (diff) | |
download | rails-52b57c662c129d72d44fa1ab9920a752c1973482.tar.gz rails-52b57c662c129d72d44fa1ab9920a752c1973482.tar.bz2 rails-52b57c662c129d72d44fa1ab9920a752c1973482.zip |
TimeWithZone instances correctly enforce DST rules. Adding TimeZone#period_for_utc
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 26 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 5 |
2 files changed, 17 insertions, 14 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index c6fa118b55..0f5d0a2ee3 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -27,7 +27,7 @@ module ActiveSupport # Returns the underlying TZInfo::TimezonePeriod for the local time def period - @period ||= get_period_for_local + @period ||= time_zone.period_for_utc(utc) end # Returns the simultaneous time in the specified zone @@ -150,6 +150,15 @@ module ActiveSupport end end + %w(asctime day hour min mon sec usec wday yday year).each do |name| + define_method(name) do + time.__send__(name) + end + end + alias_method :ctime, :asctime + alias_method :mday, :day + alias_method :month, :mon + def to_a time.to_a[0, 8].push(dst?, zone) end @@ -206,20 +215,9 @@ module ActiveSupport # Send the missing method to time instance, and wrap result in a new TimeWithZone with the existing time_zone def method_missing(sym, *args, &block) - result = time.__send__(sym, *args, &block) - result = result.change_time_zone(time_zone) if result.acts_like?(:time) + result = utc.__send__(sym, *args, &block) + result = result.in_time_zone(time_zone) if result.acts_like?(:time) result end - - private - def get_period_for_local - t = time - begin - time_zone.period_for_local(t, true) - rescue ::TZInfo::PeriodNotFound # failover logic from TzTime - t -= 1.hour - retry - end - end end end diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 4f2fc5e44b..ced823f052 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -212,6 +212,11 @@ class TimeZone end # Available so that TimeZone instances respond like TZInfo::Timezone instances + def period_for_utc(time) + tzinfo.period_for_utc(time) + end + + # Available so that TimeZone instances respond like TZInfo::Timezone instances def period_for_local(time, dst=true) tzinfo.period_for_local(time, dst) end |