From 3f22dd97af307afb857f8dbc3b545f82a9517d45 Mon Sep 17 00:00:00 2001 From: "Konstantin V. Borisov" Date: Thu, 4 Jun 2020 15:20:07 +0700 Subject: * use Setting.start_of_week setting for query filters "w", "lw", "l2w" and "nw" diff --git a/app/models/query.rb b/app/models/query.rb index 45e9882a7..881a75fb7 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -1271,25 +1271,25 @@ class Query < ActiveRecord::Base sql = relative_date_clause(db_table, db_field, 1, 1, is_custom_filter) when "w" # = this week - first_day_of_week = l(:general_first_day_of_week).to_i + first_day_of_week = Redmine::Helpers::Calendar.first_wday day_of_week = User.current.today.cwday days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) sql = relative_date_clause(db_table, db_field, - days_ago, - days_ago + 6, is_custom_filter) when "lw" # = last week - first_day_of_week = l(:general_first_day_of_week).to_i + first_day_of_week = Redmine::Helpers::Calendar.first_wday day_of_week = User.current.today.cwday days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) sql = relative_date_clause(db_table, db_field, - days_ago - 7, - days_ago - 1, is_custom_filter) when "l2w" # = last 2 weeks - first_day_of_week = l(:general_first_day_of_week).to_i + first_day_of_week = Redmine::Helpers::Calendar.first_wday day_of_week = User.current.today.cwday days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) sql = relative_date_clause(db_table, db_field, - days_ago - 14, - days_ago - 1, is_custom_filter) when "nw" # = next week - first_day_of_week = l(:general_first_day_of_week).to_i + first_day_of_week = Redmine::Helpers::Calendar.first_wday day_of_week = User.current.today.cwday from = -(day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) + 7 sql = relative_date_clause(db_table, db_field, from, from + 6, is_custom_filter) diff --git a/lib/redmine/helpers/calendar.rb b/lib/redmine/helpers/calendar.rb index 45329d7dc..08d23365a 100644 --- a/lib/redmine/helpers/calendar.rb +++ b/lib/redmine/helpers/calendar.rb @@ -66,7 +66,7 @@ module Redmine # Return the first day of week # 1 = Monday ... 7 = Sunday - def first_wday + def self.first_wday case Setting.start_of_week.to_i when 1 @first_dow ||= (1 - 1)%7 + 1 -- 2.19.0 From 8e7c7da5ca2a05e100f0a97123c7cb72f6cb18f4 Mon Sep 17 00:00:00 2001 From: "Konstantin V. Borisov" Date: Thu, 4 Jun 2020 15:49:01 +0700 Subject: * fix calendar static `first_wday` method diff --git a/lib/redmine/helpers/calendar.rb b/lib/redmine/helpers/calendar.rb index 08d23365a..339fd68b4 100644 --- a/lib/redmine/helpers/calendar.rb +++ b/lib/redmine/helpers/calendar.rb @@ -66,17 +66,15 @@ module Redmine # Return the first day of week # 1 = Monday ... 7 = Sunday + # taking into account the Setting.start_of_week preference def self.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 - end + wday = Setting.start_of_week.to_i + wday = l(:general_first_day_of_week).to_i unless [1, 6, 7].include? wday + (wday - 1) % 7 + 1 + end + + def first_wday + @first_dow ||= Calendar.first_wday end def last_wday -- 2.19.0