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 /railties/lib | |
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 'railties/lib')
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb | 10 |
2 files changed, 15 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index f58e6ba653..4d5bb364b2 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -92,6 +92,7 @@ module Rails cookie_serializer_config_exist = File.exist?('config/initializers/cookies_serializer.rb') callback_terminator_config_exist = File.exist?('config/initializers/callback_terminator.rb') active_record_belongs_to_required_by_default_config_exist = File.exist?('config/initializers/active_record_belongs_to_required_by_default.rb') + to_time_preserves_timezone_config_exist = File.exist?('config/initializers/to_time_preserves_timezone.rb') action_cable_config_exist = File.exist?('config/cable.yml') ssl_options_exist = File.exist?('config/initializers/ssl_options.rb') rack_cors_config_exist = File.exist?('config/initializers/cors.rb') @@ -112,6 +113,10 @@ module Rails remove_file 'config/initializers/active_record_belongs_to_required_by_default.rb' end + unless to_time_preserves_timezone_config_exist + remove_file 'config/initializers/to_time_preserves_timezone.rb' + end + unless action_cable_config_exist template 'config/cable.yml' end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb new file mode 100644 index 0000000000..8674be3227 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Preserve the timezone of the receiver when calling to `to_time`. +# Ruby 2.4 will change the behavior of `to_time` to preserve the timezone +# when converting to an instance of `Time` instead of the previous behavior +# of converting to the local system timezone. +# +# Rails 5.0 introduced this config option so that apps made with earlier +# versions of Rails are not affected when upgrading. +ActiveSupport.to_time_preserves_timezone = true |