@@ -21,6 +21,7 @@ def person_ids_for_query
2121 end
2222
2323 def load_activity_data ( scope : nil , year : nil )
24+ @week_start_day = parse_week_start_day
2425 @activity_filters = parse_activity_filters
2526 effective_scope = scope || default_recent_scope
2627 @activity_entries = build_activity_entries ( scope : effective_scope , filters : @activity_filters )
@@ -29,6 +30,7 @@ def load_activity_data(scope: nil, year: nil)
2930 @contribution_years = contribution_years
3031 @contribution_year = year || select_contribution_year ( @contribution_years )
3132 @contribution_weeks , @contribution_month_spans = build_contribution_weeks ( @contribution_year , filters : @activity_filters )
33+ @weekday_labels = WeekCalculation . weekday_labels ( @week_start_day )
3234 end
3335
3436 def default_recent_scope
@@ -179,28 +181,29 @@ def build_contribution_weeks(year, filters: nil)
179181 return [ [ ] , [ ] ] if ids . blank?
180182
181183 year = year . to_i
182- start_date = Date . commercial ( year , 1 , 1 )
183- end_date = Date . commercial ( year , Date . new ( year , 12 , 28 ) . cweek , 7 )
184+ wday_start = @week_start_day || WeekCalculation :: DEFAULT_WEEK_START
185+ start_date , end_date = WeekCalculation . year_weeks_range ( year , wday_start )
184186
185187 counts = build_filtered_contribution_counts ( start_date , end_date , filters )
186188
187189 total_days = ( end_date - start_date ) . to_i + 1
188190 days = ( 0 ...total_days ) . map do |idx |
189- date = start_date + idx . days
191+ date = start_date + idx
190192 count = counts [ date ] || 0
191193 { date : date , count : count , level : contribution_level ( count ) }
192194 end
193195
194196 weeks_data = days . each_slice ( 7 ) . map do |week_days |
195197 first_day = week_days . first [ :date ]
196- { days : week_days , year : first_day . cwyear , week : first_day . cweek , count : week_days . sum { |d | d [ :count ] } }
198+ week_num = WeekCalculation . week_number ( first_day , year , wday_start )
199+ { days : week_days , year : year , week : week_num , count : week_days . sum { |d | d [ :count ] } }
197200 end
198201
199202 weeks_data . each do |week |
200203 next if week [ :days ] . length == 7
201204 missing = 7 - week [ :days ] . length
202205 missing . times do |idx |
203- date = week [ :days ] . last [ :date ] + ( idx + 1 ) . days
206+ date = week [ :days ] . last [ :date ] + ( idx + 1 )
204207 week [ :days ] << { date : date , count : 0 , level : 0 }
205208 end
206209 end
@@ -305,6 +308,10 @@ def parse_activity_filters
305308 params [ :filters ] . select { |f | ALL_ACTIVITY_FILTERS . include? ( f ) }
306309 end
307310
311+ def parse_week_start_day
312+ WeekCalculation . parse_week_start ( params [ :week_start ] )
313+ end
314+
308315 def parse_activity_date
309316 Date . iso8601 ( params [ :date ] )
310317 rescue ArgumentError
0 commit comments