@@ -128,6 +128,17 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
128
128
return arrays ;
129
129
} ;
130
130
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
+
131
142
$scope . select = function ( date ) {
132
143
if ( $scope . datepickerMode === self . minMode ) {
133
144
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
236
247
}
237
248
238
249
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 ;
241
251
while ( i < n ) {
242
- dates [ i ++ ] = new Date ( current ) ;
252
+ date = new Date ( current ) ;
253
+ ctrl . fixTimeZone ( date ) ;
254
+ dates [ i ++ ] = date ;
243
255
current . setDate ( current . getDate ( ) + 1 ) ;
244
256
}
245
257
return dates ;
@@ -341,10 +353,13 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
341
353
342
354
ctrl . _refreshView = function ( ) {
343
355
var months = new Array ( 12 ) ,
344
- year = ctrl . activeDate . getFullYear ( ) ;
356
+ year = ctrl . activeDate . getFullYear ( ) ,
357
+ date ;
345
358
346
359
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 ) , {
348
363
uid : scope . uniqueId + '-' + i
349
364
} ) ;
350
365
}
@@ -401,10 +416,12 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
401
416
}
402
417
403
418
ctrl . _refreshView = function ( ) {
404
- var years = new Array ( range ) ;
419
+ var years = new Array ( range ) , date ;
405
420
406
421
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 ) , {
408
425
uid : scope . uniqueId + '-' + i
409
426
} ) ;
410
427
}
0 commit comments