From c9c5788a527b70d7f983e2b4b47e3afd863d9f48 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sat, 23 Apr 2016 14:46:50 +0100 Subject: 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. --- activesupport/lib/active_support.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activesupport/lib/active_support.rb') diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 72777baecd..11569add37 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -26,6 +26,7 @@ require "active_support/dependencies/autoload" require "active_support/version" require "active_support/logger" require "active_support/lazy_load_hooks" +require "active_support/core_ext/date_and_time/compatibility" module ActiveSupport extend ActiveSupport::Autoload @@ -85,6 +86,14 @@ module ActiveSupport def self.halt_callback_chains_on_return_false=(value) Callbacks.halt_and_display_warning_on_return_false = value end + + def self.to_time_preserves_timezone + DateAndTime::Compatibility.preserve_timezone + end + + def self.to_time_preserves_timezone=(value) + DateAndTime::Compatibility.preserve_timezone = value + end end autoload :I18n, "active_support/i18n" -- cgit v1.2.3