-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Week formatter fix in date filter (Comply to ISO8601) #10313
Conversation
CLAs look good, thanks! |
@yannickadam thnx for the PR. Could you please squash 2 commits into one and change the commit message to follow our conventions (https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines)? Thnx |
…O8601 Week formatter ("w" and "ww") in date filter was considering Sunday as the first day of the week. To comply with ISO8601, this has been changed to Monday. Closes angular#10314
805c3a6
to
80115c4
Compare
@pkozlowski-opensource Sorry - squashed & updated commit msg. |
Looking into it more carefully it seems like there are more corner cases, especially around "week zero" - specifically I'm not sure that the week no 0 is a valid value in ISO8601 so we definitively need more tests around those corner cases. If I'm not mistaken, all those tests should be passing: it('should format week number correctly (as per ISO_8601)', function () {
expect(date(new angular.mock.TzDate(+5, '2012-01-01T12:00:00.000Z'), 'EEE (ww)')).toEqual('Sun (01)');
expect(date(new angular.mock.TzDate(+5, '2012-01-07T12:00:00.000Z'), 'EEE (ww)')).toEqual('Sat (01)');
expect(date(new angular.mock.TzDate(+5, '2012-01-03T12:00:00.000Z'), 'EEE (ww)')).toEqual('Tue (01)');
expect(date(new angular.mock.TzDate(+5, '2013-01-11T12:00:00.000Z'), 'EEE (ww)')).toEqual('Fri (02)');
expect(date(new angular.mock.TzDate(+5, '2013-01-13T12:00:00.000Z'), 'EEE (ww)')).toEqual('Sun (02)');
}); On top of this I think that the current doc is wrong as it suggest that a week number can be zero:
while I don't think it is true. All in all I think that we need to fix those issues but this PR requires more work. |
One last remark - while the problem raised here is valid fixing it might be seen as a breaking change, especially in countries where Sun is traditionally counted as a first of a week. |
Indeed, many countries use Sunday as the starting day of the week. Taken from this SO answer: http://stackoverflow.com/questions/727471/how-do-i-get-the-first-day-of-the-week-for-the-current-locale-php-l8n (001 is "The World")
I've looked at the Java doc for the Gregorian Calendar, and here is an extract:
So a solution can be built to handle any starting day of the week (even though it is not described in ISO8601). About the test cases, I agree that more should be written. Week 0 does not truly exists. It is Week 52/53 from the previous year. In your first test, Sun 01 2012 is contained in Week 52 Year 2011. To manage this issue, PHP provides a ISO8601 year: To recap the todo list:
Questions:
Coming back to this pull-request, I believe it does "fix" the current behavior according to Angular's doc/specification. The work that needs to be done to make it perfect falls in the "feature" category :) |
@yannickadam so I took some time to look into the existing implementation and the ISO standard for week numbers and I think that the current implementation deviates from the ISO standard in 2 ways:
So I think that the current implementation shouldn't be called ISO-compliant - it simply doesn't follow the standard... And frankly, looking at the ISO spec that mandates turning zero-week into a 52/53 week of a previous year ... I'm not sure this is a standard worth following. I think it might confuse people even more. Now, given all this, here is my proposal:
How does it sound? I'm going to send a PR with tests that document the current behaviour shortly. |
…ting The existing documentation claims that dateFilter determines week no according to the ISO8601 standard, but this is not the case as illustrated by tests in this PR. More specifically, the implementation deviates from ISO8601 in 2 important aspects: - impl assumes Sun to be the first day of a week, ISO8601 mandates Mon - impl allows weeks 0 (for years starting on Fri, Sat) while ISO8601 would mark them as a week 52/53 of a previous year. Fixes angular#10314 Closes angular#10313
…ting The existing documentation claims that dateFilter determines week no according to the ISO8601 standard, but this is not the case as illustrated by tests in this PR. More specifically, the implementation deviates from ISO8601 in 2 important aspects: - impl assumes Sun to be the first day of a week, ISO8601 mandates Mon - impl allows weeks 0 (for years starting on Fri, Sat) while ISO8601 would mark them as a week 52/53 of a previous year. Fixes angular#10314 Closes angular#10313
…ting The existing documentation claims that dateFilter determines week no according to the ISO8601 standard, but this is not the case as illustrated by tests in this PR. More specifically, the implementation deviates from ISO8601 in 2 important aspects: - impl assumes Sun to be the first day of a week, ISO8601 mandates Mon - impl allows weeks 0 (for years starting on Fri, Sat) while ISO8601 would mark them as a week 52/53 of a previous year. Fixes angular#10314 Closes angular#10313
…ting The existing documentation claims that dateFilter determines week no according to the ISO8601 standard, but this is not the case as illustrated by tests in this PR. More specifically, the implementation deviates from ISO8601 in 2 important aspects: - impl assumes Sun to be the first day of a week, ISO8601 mandates Mon - impl allows weeks 0 (for years starting on Fri, Sat) while ISO8601 would mark them as a week 52/53 of a previous year. Fixes angular#10314 Closes angular#10313
ISO8601 mandates that a week starts on a Monday, and ends on a Sunday.
The test case was on a Friday, and did not show that W3 was returned instead of W2.
http://plnkr.co/edit/897MdGDME67aIQmLpzqZ