aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorScott Fleckenstein <nullstyle@gmail.com>2008-05-07 06:54:07 -0700
committergbuesing <gbuesing@gmail.com>2008-05-08 19:25:31 -0500
commiteb5b93be74ed3eca925c1ab9bd4739919ae39a41 (patch)
tree47e40b6cdb3a13911d2c3ff75761b4e7c1e9775a /activesupport
parentbcb090c56b842a76397e0ea32f54c942fd11910e (diff)
downloadrails-eb5b93be74ed3eca925c1ab9bd4739919ae39a41.tar.gz
rails-eb5b93be74ed3eca925c1ab9bd4739919ae39a41.tar.bz2
rails-eb5b93be74ed3eca925c1ab9bd4739919ae39a41.zip
Fix Time.zone.parse from stripping time zone information and make Time aware attribute methods use Time.zone.parse instead of to_time
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb3
-rw-r--r--activesupport/test/time_zone_test.rb8
2 files changed, 11 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 9cdc2a74ed..2342cd182c 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -214,6 +214,9 @@ class TimeZone
# Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
def parse(str, now=now)
time = Time.parse(str, now) rescue DateTime.parse(str)
+ unless time.is_a?(DateTime) || Date._parse(str)[:offset].nil?
+ time += time.in_time_zone(self).utc_offset - time.utc_offset
+ end
ActiveSupport::TimeWithZone.new(nil, self, time)
end
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 2f06c347a1..dd70186676 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -173,6 +173,14 @@ class TimeZoneTest < Test::Unit::TestCase
assert_equal zone, twz.time_zone
end
+ def test_parse_string_with_timezone
+ (-11..13).each do |timezone_offset|
+ zone = TimeZone[timezone_offset]
+ twz = zone.parse('1999-12-31 19:00:00')
+ assert_equal twz, zone.parse(twz.to_s)
+ end
+ end
+
def test_parse_with_old_date
silence_warnings do # silence warnings raised by tzinfo gem
zone = TimeZone['Eastern Time (US & Canada)']