Fixes #3341 - Reports do not show week 53

This commit is contained in:
Mantas 2020-12-18 12:20:17 +02:00 committed by Mantas Masalskis
parent e5cd8467d4
commit e2e9ebffaf
3 changed files with 24 additions and 1 deletions

View file

@ -456,6 +456,7 @@ class TimePicker extends App.Controller
selectTimeYear: (e) => selectTimeYear: (e) =>
e.preventDefault() e.preventDefault()
@ui.params.year = $(e.target).data('type') @ui.params.year = $(e.target).data('type')
@_timeSlotPicker()
$(e.target).parent().parent().find('li').removeClass('active') $(e.target).parent().parent().find('li').removeClass('active')
$(e.target).parent().addClass('active') $(e.target).parent().addClass('active')
App.Event.trigger('ui:report:rerender') App.Event.trigger('ui:report:rerender')
@ -523,7 +524,10 @@ class TimePicker extends App.Controller
] ]
@timeRangeWeek = [] @timeRangeWeek = []
for item in [1..52]
numberOfWeeks = App.PrettyDate.getISOWeeks(@ui.params.year)
for item in [1..numberOfWeeks]
record = { record = {
display: item display: item
value: item value: item

View file

@ -137,3 +137,15 @@ class App.PrettyDate
while num.toString().length < digits while num.toString().length < digits
num = '0' + num num = '0' + num
num num
@getISOWeeks: (year) ->
dayNumber = new Date("#{year}-01-01").getDay()
isLeap = new Date("#{year}-02-29").getMonth() == 1
# check for a Jan 1 that's a Thursday or a leap year that has a
# Wednesday jan 1. Otherwise it's 52
if dayNumber == 4 || isLeap && dayNumber == 3
53
else
52

View file

@ -368,3 +368,10 @@ test("check pretty date", function() {
} }
}); });
test("PrettyDate getISOWeeks", function() {
equal(App.PrettyDate.getISOWeeks(2026), 53, '53 weeks')
equal(App.PrettyDate.getISOWeeks(2020), 53, 'leap year and 53 weeks')
equal(App.PrettyDate.getISOWeeks(2019), 52, '52 weeks')
equal(App.PrettyDate.getISOWeeks(2024), 52, 'leap year and 52 weeks')
})