From 996abfa4dac016d468a437368da4efe9c630c087 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Tue, 21 Oct 2025 12:07:53 +0200 Subject: [PATCH] Fix deprecation warning for `to_time` Warning was: > DEPRECATION WARNING: `to_time` will always preserve the full timezone > rather than offset of the receiver in Rails 8.1. To opt in to the new > behavior, set `config.active_support.to_time_preserves_timezone = > :zone`. Actually we were already using `:zone`, but it was set in a file required late in the loading process. Moving it to `config/application.rb` fixes the deprecation warning. --- config/application.rb | 7 +++++++ config/initializers/new_framework_defaults_8_0.rb | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/config/application.rb b/config/application.rb index 7ac71404e30..896096d04dc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -167,6 +167,13 @@ module OpenProject # Include tstzrange columns in the list of time zone aware types ActiveRecord::Base.time_zone_aware_types += [:tstzrange] + # Specifies whether `to_time` methods preserve the UTC offset of their receivers + # or preserves the timezone. Rails 8.0+ default is `:zone`. + # If set to `:zone`, `to_time` methods will use the timezone of their receivers. + # If set to `:offset`, `to_time` methods will use the UTC offset. + # If `false`, `to_time` methods will convert to the local system UTC offset instead. + config.active_support.to_time_preserves_timezone = :zone + # Activate being able to specify the format in which full_message works. # Doing this, it is e.g. possible to avoid having the format of '%{attribute} %{message}' which # will always prepend the attribute name to the error message. diff --git a/config/initializers/new_framework_defaults_8_0.rb b/config/initializers/new_framework_defaults_8_0.rb index 924b1115b8a..726139e7efa 100644 --- a/config/initializers/new_framework_defaults_8_0.rb +++ b/config/initializers/new_framework_defaults_8_0.rb @@ -39,14 +39,6 @@ # Read the Guide for Upgrading Ruby on Rails for more info on each option. # https://guides.rubyonrails.org/upgrading_ruby_on_rails.html -### -# Specifies whether `to_time` methods preserve the UTC offset of their receivers or preserves the timezone. -# If set to `:zone`, `to_time` methods will use the timezone of their receivers. -# If set to `:offset`, `to_time` methods will use the UTC offset. -# If `false`, `to_time` methods will convert to the local system UTC offset instead. -#++ -Rails.application.config.active_support.to_time_preserves_timezone = :zone - ### # When both `If-Modified-Since` and `If-None-Match` are provided by the client # only consider `If-None-Match` as specified by RFC 7232 Section 6.