@@ -128,6 +128,17 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
128128 return arrays ;
129129 } ;
130130
131+ // Fix a hard-reprodusible bug with timezones
132+ // The bug depends on OS, browser, current timezone and current date
133+ // i.e.
134+ // var date = new Date(2014, 0, 1);
135+ // console.log(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours());
136+ // can result in "2013 11 31 23" because of the bug.
137+ this . fixTimeZone = function ( date ) {
138+ var hours = date . getHours ( ) ;
139+ date . setHours ( hours === 23 ? hours + 2 : 0 ) ;
140+ } ;
141+
131142 $scope . select = function ( date ) {
132143 if ( $scope . datepickerMode === self . minMode ) {
133144 var dt = ngModelCtrl . $viewValue ? new Date ( ngModelCtrl . $viewValue ) : new Date ( 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ;
@@ -236,10 +247,11 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
236247 }
237248
238249 function getDates ( startDate , n ) {
239- var dates = new Array ( n ) , current = new Date ( startDate ) , i = 0 ;
240- current . setHours ( 12 ) ; // Prevent repeated dates because of timezone bug
250+ var dates = new Array ( n ) , current = new Date ( startDate ) , i = 0 , date ;
241251 while ( i < n ) {
242- dates [ i ++ ] = new Date ( current ) ;
252+ date = new Date ( current ) ;
253+ ctrl . fixTimeZone ( date ) ;
254+ dates [ i ++ ] = date ;
243255 current . setDate ( current . getDate ( ) + 1 ) ;
244256 }
245257 return dates ;
@@ -341,10 +353,13 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
341353
342354 ctrl . _refreshView = function ( ) {
343355 var months = new Array ( 12 ) ,
344- year = ctrl . activeDate . getFullYear ( ) ;
356+ year = ctrl . activeDate . getFullYear ( ) ,
357+ date ;
345358
346359 for ( var i = 0 ; i < 12 ; i ++ ) {
347- months [ i ] = angular . extend ( ctrl . createDateObject ( new Date ( year , i , 1 ) , ctrl . formatMonth ) , {
360+ date = new Date ( year , i , 1 ) ;
361+ ctrl . fixTimeZone ( date ) ;
362+ months [ i ] = angular . extend ( ctrl . createDateObject ( date , ctrl . formatMonth ) , {
348363 uid : scope . uniqueId + '-' + i
349364 } ) ;
350365 }
@@ -401,10 +416,12 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
401416 }
402417
403418 ctrl . _refreshView = function ( ) {
404- var years = new Array ( range ) ;
419+ var years = new Array ( range ) , date ;
405420
406421 for ( var i = 0 , start = getStartingYear ( ctrl . activeDate . getFullYear ( ) ) ; i < range ; i ++ ) {
407- years [ i ] = angular . extend ( ctrl . createDateObject ( new Date ( start + i , 0 , 1 ) , ctrl . formatYear ) , {
422+ date = new Date ( start + i , 0 , 1 ) ;
423+ ctrl . fixTimeZone ( date ) ;
424+ years [ i ] = angular . extend ( ctrl . createDateObject ( date , ctrl . formatYear ) , {
408425 uid : scope . uniqueId + '-' + i
409426 } ) ;
410427 }
0 commit comments