diff options
author | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 14:46:50 +0100 |
---|---|---|
committer | Andrew White <andrew.white@unboxedconsulting.com> | 2016-04-23 15:03:50 +0100 |
commit | c9c5788a527b70d7f983e2b4b47e3afd863d9f48 (patch) | |
tree | 3b06bbd1555d74180ea48ad5a1ec6bbd5284261b /activesupport/test/core_ext/date_time_ext_test.rb | |
parent | 1ffa1a852e79feee9d4793fb60992a920909c316 (diff) | |
download | rails-c9c5788a527b70d7f983e2b4b47e3afd863d9f48.tar.gz rails-c9c5788a527b70d7f983e2b4b47e3afd863d9f48.tar.bz2 rails-c9c5788a527b70d7f983e2b4b47e3afd863d9f48.zip |
Add compatibility for Ruby 2.4 `to_time` changes
In Ruby 2.4 the `to_time` method for both `DateTime` and `Time` will
preserve the timezone of the receiver when converting to an instance
of `Time`. Since Rails 5.0 will support Ruby 2.2, 2.3 and later we
need to introduce a compatibility layer so that apps that upgrade do
not break. New apps will have a config initializer file that defaults
to match the new Ruby 2.4 behavior going forward.
For information about the changes to Ruby see:
https://bugs.ruby-lang.org/issues/12189
https://bugs.ruby-lang.org/issues/12271
Fixes #24617.
Diffstat (limited to 'activesupport/test/core_ext/date_time_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 16efeeadd5..d57e71df3b 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -40,6 +40,14 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase Time::DATE_FORMATS.delete(:custom) end + def test_getlocal + with_env_tz 'US/Eastern' do + assert_equal Time.local(2016, 3, 11, 10, 11, 12), DateTime.new(2016, 3, 11, 15, 11, 12, 0).getlocal + assert_equal Time.local(2016, 3, 21, 11, 11, 12), DateTime.new(2016, 3, 21, 15, 11, 12, 0).getlocal + assert_equal Time.local(2016, 4, 1, 11, 11, 12), DateTime.new(2016, 4, 1, 16, 11, 12, Rational(1,24)).getlocal + end + end + def test_to_date assert_equal Date.new(2005, 2, 21), DateTime.new(2005, 2, 21, 14, 30, 0).to_date end |