Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcec8fa

Browse files
committedDec 3, 2014
Fixed week formatter in date filter to comply with ISO8601 (Weeks are from
Monday to Sunday). Also updated the test case accordingly.
1 parent 32806ca commit fcec8fa

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
 

‎src/ng/filter/filters.js

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ 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
239-
var date;
238+
var secondWeek = new angular.mock.TzDate(+5, '2013-01-13T12:00:00.000Z'); //Sunday Jan 13, 2013
239+
240+
var date;
240241

241242
beforeEach(inject(function($filter) {
242243
date = $filter('date');

0 commit comments

Comments
 (0)
This repository has been archived.