diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index f8cdf1279f..2755ef90f3 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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 + scope.weekNumbers.push(getISO8601WeekNumber(scope.rows[r][3].date)); + } } }; diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 1eb14a434d..c6a86a2543 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -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() {