diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index de5ce6c33d..735277ad97 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -9,6 +9,13 @@ module ActiveSupport config.eager_load_namespaces << ActiveSupport + initializer "active_support.remove_deprecated_time_with_zone_name" do |app| + if app.config.active_support.remove_deprecated_time_with_zone_name + require "active_support/time_with_zone" + TimeWithZone.singleton_class.remove_method(:name) + end + end + initializer "active_support.set_authenticated_message_encryption" do |app| config.after_initialize do unless app.config.active_support.use_authenticated_message_encryption.nil? diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index c9b5d0d3fc..47a969ef4a 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -45,6 +45,8 @@ module ActiveSupport ActiveSupport::Deprecation.warn(<<~EOM) ActiveSupport::TimeWithZone.name has been deprecated and from Rails 7.1 will use the default Ruby implementation. + You can set `config.active_support.remove_deprecated_time_with_zone_name = true` + to enable thew new behavior now. EOM "Time" diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index f6ae08bb5d..0e38c79503 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -50,6 +50,7 @@ module ActiveSupport "Hash" => "hash" } end + TYPE_NAMES["ActiveSupport::TimeWithZone"] = TYPE_NAMES["Time"] FORMATTING = { "symbol" => Proc.new { |symbol| symbol.to_s }, diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index 46ea0c8797..022df2955f 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -134,6 +134,14 @@ module XmlMiniTest assert_xml("1993-02-24T12:00:00+09:00") end + test "#to_tag accepts ActiveSupport::TimeWithZone types" do + time = ActiveSupport::TimeWithZone.new(Time.new(1993, 02, 24, 12, 0, 0, "+09:00"), ActiveSupport::TimeZone["Europe/Paris"]) + ActiveSupport::TimeWithZone.stub(:name, "ActiveSupport::TimeWithZone") do + @xml.to_tag(:b, time, @options) + assert_xml("1993-02-24T13:00:00+01:00") + end + end + test "#to_tag accepts array types" do @xml.to_tag(:b, ["first_name", "last_name"], @options) assert_xml("first_namelast_name") diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 3f8f58c41e..4e7c4c9d83 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -209,6 +209,7 @@ module Rails if respond_to?(:active_support) active_support.hash_digest_class = OpenSSL::Digest::SHA256 active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256 + active_support.remove_deprecated_time_with_zone_name = true end else raise "Unknown version #{target_version.to_s.inspect}"