-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Conversation
stephanmullerNL
commented
Jan 6, 2015
- Reset count at start of year
- Improved algorithm (week number was off by +1) (taken from http://stackoverflow.com/a/7765814/124238)
- Updated tests
- Reset count at start of year - Improved algorithm (week number was off by +1) (taken from http://stackoverflow.com/a/7765814/124238) - Updated tests
I would highly appreciate it if the project collaborators could review this PR. I'm building an application which is impacted by this bug. Thanks! |
I haven't look at why yet, but I tried this PR and I am having issues. The boundary between Dec 2010 and January 2011 still shows week 53. I think this is because my calendar starts on sunday but the ISO weeks start on monday. |
This PR fixes the calculation, however, the way the UI is implemented right now, it's just not possible to display ISO8601 week numbers if your week doesn't start on Monday. "It makes sense to start the week on Sunday, the last day of the weekend", said no one ever. |
I looked a bit more into ISO 8601, and apparently it is part of the standard that the week must start on a Monday. Hence, supporting ISO 8601 week numbers and having the week start on Sunday are mutually exclusive and prone to errors. |
This works great for me:
Taken from here: http://stackoverflow.com/a/6117889/2173353
And I have kept all your other patches. |
@DumboJet DumboJet, that method looks like it does exactly the same as my current fix. I'm not in a position to check right now but are you sure your code gives different output than mine? |
Hm... Probably I had a different version of the lib (I was using ui-bootstrap-tpls-0.11.0.js - I see there is version 12 now...). Here is what I used to have:
But I've just run this test in my console with your getISO8601WeekNumber():
Seems to produce slightly different results. |
Well, according to this: |
It seems I overlooked some details, you are right. I pushed a fix. However, when using Sunday as the starting day of the week your code is also incorrect. As I mentioned before, I believe this is because the ISO8601 week number and starting the week at sunday are mutually exclusive. I'm still not sure how to approach that problem. |
- Improved algorithm yet again - Updated tests
Yes, I know... Using Sunday as a first day indeed creates problems. Actually, I don't even know if it makes sense to apply ISO on that case... |
Agreed. I don't think it does either. |