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

docs(dateFilter): fix docs to match implementation for week no formatting #10445

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}:
Expand Down
30 changes: 30 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down