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

bug #2506 Datepicker displays wrong week numbers #2517

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst

if ( scope.showWeeks ) {
scope.weekNumbers = [];
var weekNumber = getISO8601WeekNumber( scope.rows[0][0].date ),
numWeeks = scope.rows.length;
while( scope.weekNumbers.push(weekNumber++) < numWeeks ) {}
var numWeeks = scope.rows.length;
for (var r = 0; r < numWeeks; r++) {
// use date at middle of the row (3) instead of 0 to avoid problems when first day is Sunday
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to change the while loop logic once the first week number (weekNumber) is determined correctly.

scope.weekNumbers.push(getISO8601WeekNumber(scope.rows[r][3].date));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the middle of the row (3), we should really be using the week number of the Monday on that row. How about looping through the first row to find the Monday on that row, and then get it's week number instead?

That way, if somebody sets starting-day=5 so that it's T F S S M T W, it won't get the week number of the Sunday and would get the week number of the Monday on that row. I think that's more expected and closer to the specification.

}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,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