Fixes #3341 - Reports do not show week 53
This commit is contained in:
parent
e5cd8467d4
commit
e2e9ebffaf
3 changed files with 24 additions and 1 deletions
|
@ -456,6 +456,7 @@ class TimePicker extends App.Controller
|
|||
selectTimeYear: (e) =>
|
||||
e.preventDefault()
|
||||
@ui.params.year = $(e.target).data('type')
|
||||
@_timeSlotPicker()
|
||||
$(e.target).parent().parent().find('li').removeClass('active')
|
||||
$(e.target).parent().addClass('active')
|
||||
App.Event.trigger('ui:report:rerender')
|
||||
|
@ -523,7 +524,10 @@ class TimePicker extends App.Controller
|
|||
]
|
||||
|
||||
@timeRangeWeek = []
|
||||
for item in [1..52]
|
||||
|
||||
numberOfWeeks = App.PrettyDate.getISOWeeks(@ui.params.year)
|
||||
|
||||
for item in [1..numberOfWeeks]
|
||||
record = {
|
||||
display: item
|
||||
value: item
|
||||
|
|
|
@ -137,3 +137,15 @@ class App.PrettyDate
|
|||
while num.toString().length < digits
|
||||
num = '0' + 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
|
||||
|
|
|
@ -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')
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue