aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/time_with_zone.rb
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-17 05:07:50 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-17 05:07:50 +0000
commit2366fdbdb1e8a5ba4ee07d94e79c2011f5821820 (patch)
tree953002ac4f33bfa52fbaab3efa879c988ccf42aa /activesupport/lib/active_support/time_with_zone.rb
parentff8b9e6b08190c45ad1e0b7c33b5687f0b5cf56c (diff)
downloadrails-2366fdbdb1e8a5ba4ee07d94e79c2011f5821820.tar.gz
rails-2366fdbdb1e8a5ba4ee07d94e79c2011f5821820.tar.bz2
rails-2366fdbdb1e8a5ba4ee07d94e79c2011f5821820.zip
Adding TimeZone#parse
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9045 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.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index ca82c2e004..984b1e43cb 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -10,12 +10,12 @@ module ActiveSupport
@period = @utc ? period : get_period_and_ensure_valid_local_time
end
- # Returns a Time instance that represents the time in time_zone
+ # Returns a Time or DateTime instance that represents the time in time_zone
def time
@time ||= utc_to_local
end
- # Returns a Time instance that represents the time in UTC
+ # Returns a Time or DateTime instance that represents the time in UTC
def utc
@utc ||= local_to_utc
end
@@ -222,11 +222,20 @@ module ActiveSupport
private
def get_period_and_ensure_valid_local_time
- @time_zone.period_for_local(@time)
- rescue ::TZInfo::PeriodNotFound
- # time is in the "spring forward" hour gap, so we're moving the time forward one hour and trying again
- @time += 1.hour
- retry
+ # we don't want a Time.local instance enforcing its own DST rules as well,
+ # so transfer time values to a utc constructor if necessary
+ @time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
+ begin
+ @time_zone.period_for_local(@time)
+ rescue ::TZInfo::PeriodNotFound
+ # time is in the "spring forward" hour gap, so we're moving the time forward one hour and trying again
+ @time += 1.hour
+ retry
+ end
+ 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?(:usec) ? time.usec : 0)
end
# Replicating logic from TZInfo::Timezone#utc_to_local because we want to cache the period in an instance variable for reuse