@@ -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,30 +1974,35 @@ 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) (UTC)
1973
1982
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1983
+ expect ( $rootScope . value . getHours ( ) ) . toBe ( 1 ) ;
1974
1984
1975
1985
// Change the timezone offset so that the display date is a day earlier
1976
1986
// This does not change the model, but our implementation
1977
1987
// internally caches a Date object with this offset
1978
- // and re-uses it if part of the date changes
1988
+ // and re-uses it if part of the Date changes.
1989
+ // See https://github.com/angular/angular.js/commit/1a1ef62903c8fdf4ceb81277d966a8eff67f0a96
1979
1990
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1980
1991
$rootScope . $apply ( function ( ) {
1981
1992
$rootScope . value = new Date ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1982
1993
} ) ;
1983
1994
expect ( inputElm . val ( ) ) . toBe ( '1999-12-31' ) ;
1984
1995
1985
- // Emptying the input should clear the cached date object
1986
- helper . changeInputValueTo ( '' ) ;
1987
-
1996
+ // At this point, the cached Date has its hours set to to 19 (00:00 - 05:00 = 19:00)
1988
1997
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1998
+
1999
+ // When changing the timezone back to UTC, the hours part of the Date should be set to
2000
+ // the default 0 (UTC) and not use the modified value of the cached Date object.
1989
2001
helper . changeInputValueTo ( '2000-01-01' ) ;
1990
2002
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1991
2003
} ) ;
1992
2004
2005
+
1993
2006
describe ( 'min' , function ( ) {
1994
2007
1995
2008
it ( 'should invalidate' , function ( ) {
0 commit comments