Skip to content
Permalink
Browse files

docs(dateFilter): fix docs to match implementation for week no format…

…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 #10314
Closes #10313

Closes #10445
  • Loading branch information
pkozlowski-opensource committed Dec 13, 2014
1 parent ef640cb commit ab41e4849370a0541e8c9c312c2516c1b97a422d
Showing with 32 additions and 2 deletions.
  1. +2 −2 src/ng/filter/filters.js
  2. +30 −0 test/ng/filter/filtersSpec.js
@@ -356,8 +356,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEw']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d
* * `'.sss' or ',sss'`: Millisecond in second, padded (000-999)
* * `'a'`: AM/PM marker
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-+1200)
* * `'ww'`: ISO-8601 week of year (00-53)
* * `'w'`: ISO-8601 week of year (0-53)
* * `'ww'`: Week of year, padded (00-53). Week 01 is the week with the first Thursday of the year
* * `'w'`: Week of year (0-53). Week 1 is the week with the first Thursday of the year
*
* `format` string can also be one of the following predefined
* {@link guide/i18n localizable formats}:
@@ -326,6 +326,36 @@ describe('filters', function() {
toEqual('2010-09-03T06:35:08-0530');
});

it('should correctly calculate week number', function() {
function formatWeek(dateToFormat) {
return date(new angular.mock.TzDate(+5, dateToFormat + 'T12:00:00.000Z'), 'ww (EEE)');
}

expect(formatWeek('2007-01-01')).toEqual('01 (Mon)');
expect(formatWeek('2007-12-31')).toEqual('53 (Mon)');

expect(formatWeek('2008-01-01')).toEqual('01 (Tue)');
expect(formatWeek('2008-12-31')).toEqual('53 (Wed)');

expect(formatWeek('2014-01-01')).toEqual('01 (Wed)');
expect(formatWeek('2014-12-31')).toEqual('53 (Wed)');

expect(formatWeek('2009-01-01')).toEqual('01 (Thu)');
expect(formatWeek('2009-12-31')).toEqual('53 (Thu)');

expect(formatWeek('2010-01-01')).toEqual('00 (Fri)');
expect(formatWeek('2010-12-31')).toEqual('52 (Fri)');

expect(formatWeek('2011-01-01')).toEqual('00 (Sat)');
expect(formatWeek('2011-01-02')).toEqual('01 (Sun)');
expect(formatWeek('2011-01-03')).toEqual('01 (Mon)');
expect(formatWeek('2011-12-31')).toEqual('52 (Sat)');

expect(formatWeek('2012-01-01')).toEqual('01 (Sun)');
expect(formatWeek('2012-01-02')).toEqual('01 (Mon)');
expect(formatWeek('2012-12-31')).toEqual('53 (Mon)');
});

it('should treat single quoted strings as string literals', function() {
expect(date(midnight, "yyyy'de' 'a'x'dd' 'adZ' h=H:m:saZ")).
toEqual('2010de axdd adZ 12=0:5:8AM-0500');

0 comments on commit ab41e48

Please sign in to comment.
You can’t perform that action at this time.