]> source.dussan.org Git - redmine.git/commitdiff
Refactor Calendar#first_wday method for improved readability and efficiency (#41188).
authorGo MAEDA <maeda@farend.jp>
Sat, 7 Sep 2024 06:34:35 +0000 (06:34 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 7 Sep 2024 06:34:35 +0000 (06:34 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@23032 e93f8b46-1217-0410-a6f0-8f06a7374b81

.rubocop_todo.yml
lib/redmine/helpers/calendar.rb

index 7eac207f6eeabdc918bf64458c328aad9a285b6f..3e48919042c426aa260da91b3d5ed795ee52565d 100644 (file)
@@ -178,10 +178,6 @@ Lint/AmbiguousRegexpLiteral:
 Lint/AssignmentInCondition:
   Enabled: false
 
-Lint/BinaryOperatorWithIdenticalOperands:
-  Exclude:
-    - 'lib/redmine/helpers/calendar.rb'
-
 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
 Lint/DuplicateBranch:
   Exclude:
@@ -290,7 +286,6 @@ Naming/MemoizedInstanceVariableName:
     - 'app/models/query.rb'
     - 'app/models/role.rb'
     - 'lib/redmine/field_format.rb'
-    - 'lib/redmine/helpers/calendar.rb'
     - 'lib/redmine/search.rb'
 
 # Configuration parameters: EnforcedStyle, AllowedPatterns.
index 69ed62b05e956db838b403d02122f6f700020aa9..9f3962236d749097933062903504917d57687287 100644 (file)
@@ -83,20 +83,19 @@ module Redmine
       # Return the first day of week
       # 1 = Monday ... 7 = Sunday
       def first_wday
-        case Setting.start_of_week.to_i
-        when 1
-          @first_dow ||= (1 - 1)%7 + 1
-        when 6
-          @first_dow ||= (6 - 1)%7 + 1
-        when 7
-          @first_dow ||= (7 - 1)%7 + 1
-        else
-          @first_dow ||= (l(:general_first_day_of_week).to_i - 1)%7 + 1
+        @first_wday ||= begin
+          start_of_week = Setting.start_of_week.to_i
+          case start_of_week
+          when 1, 6, 7
+            ((start_of_week - 1) % 7) + 1
+          else
+            ((l(:general_first_day_of_week).to_i - 1) % 7) + 1
+          end
         end
       end
 
       def last_wday
-        @last_dow ||= (first_wday + 5)%7 + 1
+        @last_wday ||= ((first_wday + 5) % 7) + 1
       end
     end
   end