Merge pull request #3258 from Platoniq/dashboard-wrong-calculate-week
Dashboard wrong calculate week
This commit is contained in:
@@ -3,12 +3,12 @@ module Dashboard::GroupSupports
|
||||
|
||||
included do
|
||||
def grouped_supports(attribute)
|
||||
supports.group_by { |v| grouping_key_for(v[attribute].to_date) }
|
||||
supports.group_by { |v| grouping_key_for(v[attribute].in_time_zone.to_date) }
|
||||
end
|
||||
|
||||
def grouping_key_for(date)
|
||||
return "#{date.cweek}/#{date.year}" if params[:group_by] == 'week'
|
||||
return "#{date.year}-#{date.month}" if params[:group_by] == 'month'
|
||||
return calculate_week(date) if params[:group_by] == "week"
|
||||
return "#{date.year}-#{date.month}" if params[:group_by] == "month"
|
||||
|
||||
date
|
||||
end
|
||||
@@ -50,4 +50,29 @@ module Dashboard::GroupSupports
|
||||
1.day
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
def calculate_week(date)
|
||||
week = date.cweek
|
||||
year = calculate_year_of_week(date)
|
||||
"#{week}/#{year}"
|
||||
end
|
||||
|
||||
def calculate_year_of_week(date)
|
||||
year = date.year
|
||||
if first_week_of_year?(date) && date.end_of_week.year != date.year
|
||||
year = year + 1
|
||||
elsif last_week_of_year?(date) && date.beginning_of_week.year != date.year
|
||||
year = year - 1
|
||||
end
|
||||
year
|
||||
end
|
||||
|
||||
def first_week_of_year?(date)
|
||||
date.cweek == 1
|
||||
end
|
||||
|
||||
def last_week_of_year?(date)
|
||||
date.cweek == 52 || date.cweek == 53
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user