aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_and_time_compatibility_test.rb
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxedconsulting.com>2016-04-23 19:34:54 +0100
committerAndrew White <andrew.white@unboxedconsulting.com>2016-04-23 19:34:54 +0100
commitee5e476aad791e41c97f2a833f41bb5899d5252b (patch)
tree45ad466560b97f542222d97432f1cca9c793dc5a /activesupport/test/core_ext/date_and_time_compatibility_test.rb
parenta424bbb2423297cc8bd80fc8b36f7169c3986a71 (diff)
downloadrails-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/date_and_time_compatibility_test.rb')
-rw-r--r--activesupport/test/core_ext/date_and_time_compatibility_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_and_time_compatibility_test.rb b/activesupport/test/core_ext/date_and_time_compatibility_test.rb
index 7cc2fae5be..11cb1469da 100644
--- a/activesupport/test/core_ext/date_and_time_compatibility_test.rb
+++ b/activesupport/test/core_ext/date_and_time_compatibility_test.rb
@@ -7,6 +7,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase
def setup
@utc_time = Time.utc(2016, 4, 23, 14, 11, 12)
+ @date_time = DateTime.new(2016, 4, 23, 14, 11, 12, 0)
@utc_offset = 3600
@system_offset = -14400
@zone = ActiveSupport::TimeZone['London']
@@ -67,6 +68,14 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase
assert_instance_of Time, time
assert_equal @utc_time, time.getutc
+ assert_instance_of Time, time.getutc
+ assert_equal @utc_offset, time.utc_offset
+
+ time = ActiveSupport::TimeWithZone.new(@date_time, @zone).to_time
+
+ assert_instance_of Time, time
+ assert_equal @date_time, time.getutc
+ assert_instance_of Time, time.getutc
assert_equal @utc_offset, time.utc_offset
end
end
@@ -79,6 +88,14 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase
assert_instance_of Time, time
assert_equal @utc_time, time.getutc
+ assert_instance_of Time, time.getutc
+ assert_equal @system_offset, time.utc_offset
+
+ time = ActiveSupport::TimeWithZone.new(@date_time, @zone).to_time
+
+ assert_instance_of Time, time
+ assert_equal @date_time, time.getutc
+ assert_instance_of Time, time.getutc
assert_equal @system_offset, time.utc_offset
end
end