aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/time_with_zone.rb
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-11 04:26:20 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-11 04:26:20 +0000
commit52b57c662c129d72d44fa1ab9920a752c1973482 (patch)
tree90e89994fc4486e5523fe45df46f5d013e184a83 /activesupport/lib/active_support/time_with_zone.rb
parent3d2177df26c8934320277a7aed84595decd94662 (diff)
downloadrails-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/active_support/time_with_zone.rb')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb26
1 files changed, 12 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