Patch #35208

Use `Time.use_zone` instead of ``

Added by Go MAEDA 9 months ago. Updated 9 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:


Category:Code cleanup/refactoring
Target version:5.0.0


When temporarily overriding a time zone, it is safer to use Time.use_zone than to update directly because Time.use_zone will reset the time zone to its original value after the execution of the given block is done.

And RuboCop Rails 2.10.0 will display Rails/TimeZoneAssignment warning when it detects code that directly updates

Index: test/unit/mailer_test.rb
--- test/unit/mailer_test.rb    (リビジョン 20961)
+++ test/unit/mailer_test.rb    (作業コピー)
@@ -386,11 +386,10 @@
     issue = Issue.find(3)
     user = User.find(1)
     %w(UTC Paris Tokyo).each do |zone|
- = zone
-      assert_match /^redmine\.issue-3\.20060719190727\.1@example\.net/, Mailer.token_for(issue, user)
+      Time.use_zone(zone) do
+        assert_match /^redmine\.issue-3\.20060719190727\.1@example\.net/, Mailer.token_for(issue, user)
+      end
-  ensure
- = zone_was

   test "#issue_add should notify project members" do

Related issues

Related to Redmine - Patch #35207: Update RuboCop Rails to 2.13 Closed

Associated revisions

Revision 20988
Added by Go MAEDA 9 months ago

Use `Time.use_zone` instead of `` (#35208).

Patch by Go MAEDA.


#1 Updated by Go MAEDA 9 months ago

  • Related to Patch #35207: Update RuboCop Rails to 2.13 added

#2 Updated by Go MAEDA 9 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Target version set to 5.0.0

Committed the patch.

Also available in: Atom PDF