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');