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

Commit 80115c4

Browse files
committed
fix(ngFilter): change week formatter in date filter to comply with ISO8601
Week formatter ("w" and "ww") in date filter was considering Sunday as the first day of the week. To comply with ISO8601, this has been changed to Monday. Closes #10314
1 parent 32806ca commit 80115c4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/ng/filter/filters.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ function getFirstThursdayOfYear(year) {
273273
function getThursdayThisWeek(datetime) {
274274
return new Date(datetime.getFullYear(), datetime.getMonth(),
275275
// 4 = index of Thursday
276-
datetime.getDate() + (4 - datetime.getDay()));
276+
//ISO8601 mandates that a week starts on Monday. Making Sunday 7 instead of 0.
277+
datetime.getDate() + 4 - (datetime.getDay() || 7));
277278
}
278279

279280
function weekGetter(size) {

test/ng/filter/filtersSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('filters', function() {
235235
var noon = new angular.mock.TzDate(+5, '2010-09-03T17:05:08.012Z'); //12pm
236236
var midnight = new angular.mock.TzDate(+5, '2010-09-03T05:05:08.123Z'); //12am
237237
var earlyDate = new angular.mock.TzDate(+5, '0001-09-03T05:05:08.000Z');
238-
var secondWeek = new angular.mock.TzDate(+5, '2013-01-11T12:00:00.000Z'); //Friday Jan 11, 2012
238+
var secondWeek = new angular.mock.TzDate(+5, '2013-01-13T12:00:00.000Z'); //Sunday Jan 13, 2013
239239
var date;
240240

241241
beforeEach(inject(function($filter) {

0 commit comments

Comments
 (0)