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

Commit

Permalink
fix(datepicker): week count issues
Browse files Browse the repository at this point in the history
- add missing semicolon
- no need for exact days match in test
- describe in spec file

Fixes #2506
Fixes #3120
Closes #2306
  • Loading branch information
a5sk4s authored and chrisirhc committed Apr 26, 2015
1 parent 82cb637 commit 39e5fd3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst

if ( scope.showWeeks ) {
scope.weekNumbers = [];
var weekNumber = getISO8601WeekNumber( scope.rows[0][0].date ),
var thursdayIndex = (4 + 7 - ctrl.startingDay) % 7,
curWeek = 0,
numWeeks = scope.rows.length;
while( scope.weekNumbers.push(weekNumber++) < numWeeks ) {}
while( curWeek < numWeeks ) {scope.weekNumbers.push(getISO8601WeekNumber( scope.rows[curWeek++][thursdayIndex].date ));}
}
};

Expand Down
73 changes: 72 additions & 1 deletion src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('datepicker directive', function () {
});

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

it('value is correct', function() {
Expand Down Expand Up @@ -2032,4 +2032,75 @@ describe('datepicker directive', function () {
expect(new Date($rootScope.date.date)).toEqual(new Date('April 15, 2015 00:00:00'));
});
});

describe('thurdays determine week count', function() {

beforeEach(inject(function() {
$rootScope.date = new Date('June 07, 2014');
}));

it('with the default starting day (sunday)', function() {
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
});

describe('when starting date', function() {
it('is monday', function() {
element = $compile('<datepicker ng-model="date" starting-day="1"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
});

it('is thursday', function() {
element = $compile('<datepicker ng-model="date" starting-day="4"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['22', '23', '24', '25', '26', '27']);
});

it('is saturday', function() {
element = $compile('<datepicker ng-model="date" starting-day="6"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['23', '24', '25', '26', '27', '28']);
});
});

describe('first week in january', function() {
beforeEach(inject(function() {
}));

it('in current year', function() {
$rootScope.date = new Date('January 07, 2014');
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['1', '2', '3', '4', '5', '6']);
});

it('in last year', function() {
$rootScope.date = new Date('January 07, 2010');
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['53', '1', '2', '3', '4', '5']);
});
});

describe('last week(s) in december', function() {
beforeEach(inject(function() {
$rootScope.date = new Date('December 07, 2014');
}));

it('in next year', function() {
element = $compile('<datepicker ng-model="date"></datepicker>')($rootScope);
$rootScope.$digest();

expect(getWeeks()).toEqual(['49', '50', '51', '52', '1', '2']);
});
});
});
});

0 comments on commit 39e5fd3

Please sign in to comment.