diff options
author | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 19:34:54 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 19:34:54 +0100 |
commit | ee5e476aad791e41c97f2a833f41bb5899d5252b (patch) | |
tree | 45ad466560b97f542222d97432f1cca9c793dc5a /activesupport/test/core_ext/time_with_zone_test.rb | |
parent | a424bbb2423297cc8bd80fc8b36f7169c3986a71 (diff) | |
download | rails-ee5e476aad791e41c97f2a833f41bb5899d5252b.tar.gz rails-ee5e476aad791e41c97f2a833f41bb5899d5252b.tar.bz2 rails-ee5e476aad791e41c97f2a833f41bb5899d5252b.zip |
Make getlocal and getutc always return instances of Time
Previously these methods could return either a DateTime or a Time
depending on how the ActiveSupport::TimeWithZone instance had
been constructed. Changing to always return an instance of Time
eliminates a possible stack level too deep error in to_time where
it was wrapping a DateTime instance.
As a consequence of this the internal time value is now always an
instance of Time in the UTC timezone, whether that's as the UTC
time directly or a representation of the local time in the timezone.
There should be no consequences of this internal change and if
there are it's a bug due to leaky abstractions.
Diffstat (limited to 'activesupport/test/core_ext/time_with_zone_test.rb')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 7acada011d..d90714acdb 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -11,10 +11,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase @utc = Time.utc(2000, 1, 1, 0) @time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] @twz = ActiveSupport::TimeWithZone.new(@utc, @time_zone) + @dt_twz = ActiveSupport::TimeWithZone.new(@utc.to_datetime, @time_zone) end def test_utc assert_equal @utc, @twz.utc + assert_instance_of Time, @twz.utc + assert_instance_of Time, @dt_twz.utc end def test_time @@ -47,6 +50,8 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_localtime assert_equal @twz.localtime, @twz.utc.getlocal + assert_instance_of Time, @twz.localtime + assert_instance_of Time, @dt_twz.localtime end def test_utc? |