Project

General

Profile

Patch #33554 ยป query_start_of_week.patch

Konstantin Borisov, 2020-06-04 17:29

View differences:

app/models/query.rb
1271 1271
      sql = relative_date_clause(db_table, db_field, 1, 1, is_custom_filter)
1272 1272
    when "w"
1273 1273
      # = this week
1274
      first_day_of_week = l(:general_first_day_of_week).to_i
1274
      first_day_of_week = Redmine::Helpers::Calendar.first_wday
1275 1275
      day_of_week = User.current.today.cwday
1276 1276
      days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
1277 1277
      sql = relative_date_clause(db_table, db_field, - days_ago, - days_ago + 6, is_custom_filter)
1278 1278
    when "lw"
1279 1279
      # = last week
1280
      first_day_of_week = l(:general_first_day_of_week).to_i
1280
      first_day_of_week = Redmine::Helpers::Calendar.first_wday
1281 1281
      day_of_week = User.current.today.cwday
1282 1282
      days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
1283 1283
      sql = relative_date_clause(db_table, db_field, - days_ago - 7, - days_ago - 1, is_custom_filter)
1284 1284
    when "l2w"
1285 1285
      # = last 2 weeks
1286
      first_day_of_week = l(:general_first_day_of_week).to_i
1286
      first_day_of_week = Redmine::Helpers::Calendar.first_wday
1287 1287
      day_of_week = User.current.today.cwday
1288 1288
      days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
1289 1289
      sql = relative_date_clause(db_table, db_field, - days_ago - 14, - days_ago - 1, is_custom_filter)
1290 1290
    when "nw"
1291 1291
      # = next week
1292
      first_day_of_week = l(:general_first_day_of_week).to_i
1292
      first_day_of_week = Redmine::Helpers::Calendar.first_wday
1293 1293
      day_of_week = User.current.today.cwday
1294 1294
      from = -(day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) + 7
1295 1295
      sql = relative_date_clause(db_table, db_field, from, from + 6, is_custom_filter)
lib/redmine/helpers/calendar.rb
66 66

  
67 67
      # Return the first day of week
68 68
      # 1 = Monday ... 7 = Sunday
69
      def first_wday
69
      def self.first_wday
70 70
        case Setting.start_of_week.to_i
71 71
        when 1
72 72
          @first_dow ||= (1 - 1)%7 + 1
73
- 
lib/redmine/helpers/calendar.rb
66 66

  
67 67
      # Return the first day of week
68 68
      # 1 = Monday ... 7 = Sunday
69
      # taking into account the Setting.start_of_week preference
69 70
      def self.first_wday
70
        case Setting.start_of_week.to_i
71
        when 1
72
          @first_dow ||= (1 - 1)%7 + 1
73
        when 6
74
          @first_dow ||= (6 - 1)%7 + 1
75
        when 7
76
          @first_dow ||= (7 - 1)%7 + 1
77
        else
78
          @first_dow ||= (l(:general_first_day_of_week).to_i - 1)%7 + 1
79
        end
71
        wday = Setting.start_of_week.to_i
72
        wday = l(:general_first_day_of_week).to_i unless [1, 6, 7].include? wday
73
        (wday - 1) % 7 + 1
74
      end
75

  
76
      def first_wday
77
        @first_dow ||= Calendar.first_wday
80 78
      end
81 79

  
82 80
      def last_wday
    (1-1/1)