Defect #2462
closedIncorrect Week Number in Spent Time Report
0%
Description
- 2008-51
- 2008-52
- 2008-1
- 2009-2
I asssume that the third week ought to show as 2009-1
Files
Related issues
Updated by Anonymous over 15 years ago
Also affects calendar. I found that problem in our redmine installation and it turns out it's related to the start of the week. Problem is that week 1 of 2009 starts on december 2008,
If you go to calendar for January 2009, the first week is week 52 of 2008, when it should be week 1 of 2009. This doesn't happen if week starts on Monday.
For any week number calculation you should use Monday as first day of week. I would submit a patch, but I don't see any quick way to fix it, I just hacked it to force monday as first day of week, regardless which language you are using.
>> d-=1 => Thu, 01 Jan 2009 >> [d.cweek,d.year,d.to_s] => [1, 2009, "2009-01-01"] >> d-=1 => Wed, 31 Dec 2008 >> [d.cweek,d.year,d.to_s] => [1, 2008, "2008-12-31"] >> d-=1 => Tue, 30 Dec 2008 >> [d.cweek,d.year,d.to_s] => [1, 2008, "2008-12-30"] >> d-=1 => Mon, 29 Dec 2008 >> [d.cweek,d.year,d.to_s] => [1, 2008, "2008-12-29"] >> d-=1 => Sun, 28 Dec 2008 >> [d.cweek,d.year,d.to_s] => [52, 2008, "2008-12-28"]
More info about week counting at http://en.wikipedia.org/wiki/ISO_week_date
Quoting:
Mutually equivalent definitions for week 01 are:
- the week with the year's first Thursday in it (the ISO 8601 definition)
- the week starting with the Monday which is nearest in time to 1 January
- the week with the year's first working day in it (if Saturdays, Sundays, and 1 January are not working days)
- the week with January 4 in it
- the first week with the majority (four or more) of its days in the starting year
- the week starting with the Monday in the period 29 December - 4 January
- the week with the Thursday in the period 1 - 7 January
- If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year.
I hope this helps fixing the problem. Also, fixing #2884 would allow a quick workaround
Updated by Anonymous over 15 years ago
Actually, it seems this bug can be fixed by using Date#cwyear instead of Date#year:
=> Fri, 26 Dec 2008 >> 7.times {d+=1; puts [d.cweek,d.cwyear,d.year,d.to_s].inspect} [52, 2008, 2008, "2008-12-27"] [52, 2008, 2008, "2008-12-28"] [1, 2009, 2008, "2008-12-29"] [1, 2009, 2008, "2008-12-30"] [1, 2009, 2008, "2008-12-31"] [1, 2009, 2009, "2009-01-01"] [1, 2009, 2009, "2009-01-02"]
So in TimelogController#report change
when 'week' @periods << "#{date_from.year}-#{date_from.to_date.cweek}" date_from = (date_from + 7.day).at_beginning_of_week
to
when 'week' @periods << "#{date_from.cwyear}-#{date_from.to_date.cweek}" date_from = (date_from + 7.day).at_beginning_of_week
Updated by Holger Just about 14 years ago
- Status changed from New to Closed
- Resolution set to Duplicate
This issue is being worked in in #5329.
Unfortunately, there are some more subtly difficulties to solve...