Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 39e5fd3

Browse files
a5sk4schrisirhc
authored andcommitted
fix(datepicker): week count issues
- add missing semicolon - no need for exact days match in test - describe in spec file Fixes #2506 Fixes #3120 Closes #2306
1 parent 82cb637 commit 39e5fd3

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

Diff for: src/datepicker/datepicker.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
281281

282282
if ( scope.showWeeks ) {
283283
scope.weekNumbers = [];
284-
var weekNumber = getISO8601WeekNumber( scope.rows[0][0].date ),
284+
var thursdayIndex = (4 + 7 - ctrl.startingDay) % 7,
285+
curWeek = 0,
285286
numWeeks = scope.rows.length;
286-
while( scope.weekNumbers.push(weekNumber++) < numWeeks ) {}
287+
while( curWeek < numWeeks ) {scope.weekNumbers.push(getISO8601WeekNumber( scope.rows[curWeek++][thursdayIndex].date ));}
287288
}
288289
};
289290

Diff for: src/datepicker/test/datepicker.spec.js

+72-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('datepicker directive', function () {
159159
});
160160

161161
it('renders the week numbers based on ISO 8601', function() {
162-
expect(getWeeks()).toEqual(['34', '35', '36', '37', '38', '39']);
162+
expect(getWeeks()).toEqual(['35', '36', '37', '38', '39', '40']);
163163
});
164164

165165
it('value is correct', function() {
@@ -2032,4 +2032,75 @@ describe('datepicker directive', function () {
20322032
expect(new Date($rootScope.date.date)).toEqual(new Date('April 15, 2015 00:00:00'));
20332033
});
20342034
});
2035+
2036+
describe('thurdays determine week count', function() {
2037+
2038+
beforeEach(inject(function() {
2039+
$rootScope.date = new Date('June 07, 2014');
2040+
}));
2041+
2042+
it('with the default starting day (sunday)', function() {
2043+
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
2044+
$rootScope.$digest();
2045+
2046+
expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
2047+
});
2048+
2049+
describe('when starting date', function() {
2050+
it('is monday', function() {
2051+
element = $compile('<datepicker ng-model="date" starting-day="1"></datepicker>')($rootScope);
2052+
$rootScope.$digest();
2053+
2054+
expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
2055+
});
2056+
2057+
it('is thursday', function() {
2058+
element = $compile('<datepicker ng-model="date" starting-day="4"></datepicker>')($rootScope);
2059+
$rootScope.$digest();
2060+
2061+
expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
2062+
});
2063+
2064+
it('is saturday', function() {
2065+
element = $compile('<datepicker ng-model="date" starting-day="6"></datepicker>')($rootScope);
2066+
$rootScope.$digest();
2067+
2068+
expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
2069+
});
2070+
});
2071+
2072+
describe('first week in january', function() {
2073+
beforeEach(inject(function() {
2074+
}));
2075+
2076+
it('in current year', function() {
2077+
$rootScope.date = new Date('January 07, 2014');
2078+
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
2079+
$rootScope.$digest();
2080+
2081+
expect(getWeeks()).toEqual(['1', '2', '3', '4', '5', '6']);
2082+
});
2083+
2084+
it('in last year', function() {
2085+
$rootScope.date = new Date('January 07, 2010');
2086+
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
2087+
$rootScope.$digest();
2088+
2089+
expect(getWeeks()).toEqual(['53', '1', '2', '3', '4', '5']);
2090+
});
2091+
});
2092+
2093+
describe('last week(s) in december', function() {
2094+
beforeEach(inject(function() {
2095+
$rootScope.date = new Date('December 07, 2014');
2096+
}));
2097+
2098+
it('in next year', function() {
2099+
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
2100+
$rootScope.$digest();
2101+
2102+
expect(getWeeks()).toEqual(['49', '50', '51', '52', '1', '2']);
2103+
});
2104+
});
2105+
});
20352106
});

0 commit comments

Comments
 (0)