Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ab41e48

Browse files
docs(dateFilter): fix docs to match implementation for week no formatting
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 #10314 Closes #10313 Closes #10445
1 parent ef640cb commit ab41e48

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/ng/filter/filters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEw']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d
356356
* * `'.sss' or ',sss'`: Millisecond in second, padded (000-999)
357357
* * `'a'`: AM/PM marker
358358
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-+1200)
359-
* * `'ww'`: ISO-8601 week of year (00-53)
360-
* * `'w'`: ISO-8601 week of year (0-53)
359+
* * `'ww'`: Week of year, padded (00-53). Week 01 is the week with the first Thursday of the year
360+
* * `'w'`: Week of year (0-53). Week 1 is the week with the first Thursday of the year
361361
*
362362
* `format` string can also be one of the following predefined
363363
* {@link guide/i18n localizable formats}:

test/ng/filter/filtersSpec.js

+30
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,36 @@ describe('filters', function() {
326326
toEqual('2010-09-03T06:35:08-0530');
327327
});
328328

329+
it('should correctly calculate week number', function() {
330+
function formatWeek(dateToFormat) {
331+
return date(new angular.mock.TzDate(+5, dateToFormat + 'T12:00:00.000Z'), 'ww (EEE)');
332+
}
333+
334+
expect(formatWeek('2007-01-01')).toEqual('01 (Mon)');
335+
expect(formatWeek('2007-12-31')).toEqual('53 (Mon)');
336+
337+
expect(formatWeek('2008-01-01')).toEqual('01 (Tue)');
338+
expect(formatWeek('2008-12-31')).toEqual('53 (Wed)');
339+
340+
expect(formatWeek('2014-01-01')).toEqual('01 (Wed)');
341+
expect(formatWeek('2014-12-31')).toEqual('53 (Wed)');
342+
343+
expect(formatWeek('2009-01-01')).toEqual('01 (Thu)');
344+
expect(formatWeek('2009-12-31')).toEqual('53 (Thu)');
345+
346+
expect(formatWeek('2010-01-01')).toEqual('00 (Fri)');
347+
expect(formatWeek('2010-12-31')).toEqual('52 (Fri)');
348+
349+
expect(formatWeek('2011-01-01')).toEqual('00 (Sat)');
350+
expect(formatWeek('2011-01-02')).toEqual('01 (Sun)');
351+
expect(formatWeek('2011-01-03')).toEqual('01 (Mon)');
352+
expect(formatWeek('2011-12-31')).toEqual('52 (Sat)');
353+
354+
expect(formatWeek('2012-01-01')).toEqual('01 (Sun)');
355+
expect(formatWeek('2012-01-02')).toEqual('01 (Mon)');
356+
expect(formatWeek('2012-12-31')).toEqual('53 (Mon)');
357+
});
358+
329359
it('should treat single quoted strings as string literals', function() {
330360
expect(date(midnight, "yyyy'de' 'a'x'dd' 'adZ' h=H:m:saZ")).
331361
toEqual('2010de axdd adZ 12=0:5:8AM-0500');

0 commit comments

Comments
 (0)