@@ -1022,15 +1022,23 @@ describe('input', function() {
1022
1022
it ( 'should be possible to override the timezone' , function ( ) {
1023
1023
var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1024
1024
1025
- helper . changeInputValueTo ( '2013-W03' ) ;
1026
- expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 0 , 17 ) ) ;
1025
+ // January 19 2013 is a Saturday
1026
+ $rootScope . $apply ( function ( ) {
1027
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
1028
+ } ) ;
1029
+
1030
+ expect ( inputElm . val ( ) ) . toBe ( '2013-W03' ) ;
1027
1031
1028
- inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+5000 ' } ) ;
1032
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+2400 ' } ) ;
1029
1033
1034
+ // To check that the timezone overwrite works, apply an offset of +24 hours.
1035
+ // Since January 19 is a Saturday, +24 will turn the formatted Date into January 20 - Sunday -
1036
+ // which is in calendar week 4 instead of 3.
1030
1037
$rootScope . $apply ( function ( ) {
1031
- // the 17. with an offset of +5000 moves the date into next week
1032
- $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 18 ) ) ;
1038
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
1033
1039
} ) ;
1040
+
1041
+ // Verifying that the displayed week is week 4 confirms that overriding the timezone worked
1034
1042
expect ( inputElm . val ( ) ) . toBe ( '2013-W04' ) ;
1035
1043
} ) ;
1036
1044
@@ -2092,30 +2100,34 @@ describe('input', function() {
2092
2100
dealoc ( formElm ) ;
2093
2101
} ) ;
2094
2102
2095
- it ( 'should not reuse the hour part of a previous date object after changing the timezone' , function ( ) {
2103
+ it ( 'should not reuse the hours part of a previous date object after changing the timezone' , function ( ) {
2096
2104
var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2097
2105
2098
2106
helper . changeInputValueTo ( '2000-01-01' ) ;
2107
+ // The Date parser sets the hours part of the Date to 0 (00:00) (UTC)
2099
2108
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2100
2109
2101
2110
// Change the timezone offset so that the display date is a day earlier
2102
2111
// This does not change the model, but our implementation
2103
2112
// internally caches a Date object with this offset
2104
- // and re-uses it if part of the date changes
2113
+ // and re-uses it if part of the Date changes.
2114
+ // See https://github.com/angular/angular.js/commit/1a1ef62903c8fdf4ceb81277d966a8eff67f0a96
2105
2115
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
2106
2116
$rootScope . $apply ( function ( ) {
2107
2117
$rootScope . value = new Date ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2108
2118
} ) ;
2109
2119
expect ( inputElm . val ( ) ) . toBe ( '1999-12-31' ) ;
2110
2120
2111
- // Emptying the input should clear the cached date object
2112
- helper . changeInputValueTo ( '' ) ;
2113
-
2121
+ // At this point, the cached Date has its hours set to to 19 (00:00 - 05:00 = 19:00)
2114
2122
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
2123
+
2124
+ // When changing the timezone back to UTC, the hours part of the Date should be set to
2125
+ // the default 0 (UTC) and not use the modified value of the cached Date object.
2115
2126
helper . changeInputValueTo ( '2000-01-01' ) ;
2116
2127
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2117
2128
} ) ;
2118
2129
2130
+
2119
2131
describe ( 'min' , function ( ) {
2120
2132
2121
2133
it ( 'should invalidate' , function ( ) {
0 commit comments