@@ -949,15 +949,23 @@ describe('input', function() {
949
949
it ( 'should be possible to override the timezone' , function ( ) {
950
950
var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
951
951
952
- helper . changeInputValueTo ( '2013-W03' ) ;
953
- expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 0 , 17 ) ) ;
952
+ // January 19 2013 is a Saturday
953
+ $rootScope . $apply ( function ( ) {
954
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
955
+ } ) ;
956
+
957
+ expect ( inputElm . val ( ) ) . toBe ( '2013-W03' ) ;
954
958
955
- inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+5000 ' } ) ;
959
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+2400 ' } ) ;
956
960
961
+ //To check that the timezone overwrite works, apply an offset of +24 hours.
962
+ //Since January 19 is a Saturday, +24 will turn the formatted Date into January 20 - Sunday -
963
+ //which is in calendar week 4 instead of 3.
957
964
$rootScope . $apply ( function ( ) {
958
- // the 17. with an offset of +5000 moves the date into next week
959
- $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 18 ) ) ;
965
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
960
966
} ) ;
967
+
968
+ // Verifying that the displayed week is week 4 confirms that overriding the timezone worked
961
969
expect ( inputElm . val ( ) ) . toBe ( '2013-W04' ) ;
962
970
} ) ;
963
971
@@ -1966,28 +1974,32 @@ describe('input', function() {
1966
1974
dealoc ( formElm ) ;
1967
1975
} ) ;
1968
1976
1969
- it ( 'should not reuse the hour part of a previous date object after changing the timezone' , function ( ) {
1977
+ it ( 'should not reuse the hours part of a previous date object after changing the timezone' , function ( ) {
1970
1978
var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1971
1979
1972
1980
helper . changeInputValueTo ( '2000-01-01' ) ;
1981
+ // The Date parser sets the hours part of the Date to 0 (00:00)
1973
1982
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1974
1983
1975
1984
// Change the timezone offset so that the display date is a day earlier
1976
1985
// This does not change the model, but our implementation
1977
1986
// internally caches a Date object with this offset
1978
- // and re-uses it if part of the date changes
1987
+ // and re-uses it if part of the Date changes.
1988
+ // See https://github.com/angular/angular.js/commit/1a1ef62903c8fdf4ceb81277d966a8eff67f0a96
1979
1989
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1980
1990
$rootScope . $apply ( function ( ) {
1981
1991
$rootScope . value = new Date ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1982
1992
} ) ;
1983
1993
expect ( inputElm . val ( ) ) . toBe ( '1999-12-31' ) ;
1984
-
1985
- // Emptying the input should clear the cached date object
1986
- helper . changeInputValueTo ( '' ) ;
1994
+ // At this point, the cached Date has its hours set to to 20 (00:00 - 05:00 = 19:00)
1987
1995
1988
1996
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1997
+
1998
+ // When changing the timezone back to UTC, the hours part of the Date should be set to
1999
+ // the default 0 and not use the 20 of the cached Date object
1989
2000
helper . changeInputValueTo ( '2000-01-01' ) ;
1990
2001
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2002
+ expect ( $rootScope . value . getHours ( ) ) . not . toBe ( 20 ) ;
1991
2003
} ) ;
1992
2004
1993
2005
describe ( 'min' , function ( ) {
0 commit comments