From e1dfa27ee05f7f1f0314abb41b4fd2ea659ac5dc Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 13 Dec 2014 20:29:56 +0100 Subject: [PATCH] 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 --- src/ng/filter/filters.js | 4 ++-- test/ng/filter/filtersSpec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index 9474918b8277..b2c5602e0874 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.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}: diff --git a/test/ng/filter/filtersSpec.js b/test/ng/filter/filtersSpec.js index 977055bf1b81..103bb1513d7e 100644 --- a/test/ng/filter/filtersSpec.js +++ b/test/ng/filter/filtersSpec.js @@ -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');