@@ -980,15 +980,23 @@ describe('input', function() {
980
980
it ( 'should be possible to override the timezone' , function ( ) {
981
981
var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
982
982
983
- helper . changeInputValueTo ( '2013-W03' ) ;
984
- expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 0 , 17 ) ) ;
983
+ // January 19 2013 is a Saturday
984
+ $rootScope . $apply ( function ( ) {
985
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
986
+ } ) ;
987
+
988
+ expect ( inputElm . val ( ) ) . toBe ( '2013-W03' ) ;
985
989
986
- inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+5000 ' } ) ;
990
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+2400 ' } ) ;
987
991
992
+ // To check that the timezone overwrite works, apply an offset of +24 hours.
993
+ // Since January 19 is a Saturday, +24 will turn the formatted Date into January 20 - Sunday -
994
+ // which is in calendar week 4 instead of 3.
988
995
$rootScope . $apply ( function ( ) {
989
- // the 17. with an offset of +5000 moves the date into next week
990
- $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 18 ) ) ;
996
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
991
997
} ) ;
998
+
999
+ // Verifying that the displayed week is week 4 confirms that overriding the timezone worked
992
1000
expect ( inputElm . val ( ) ) . toBe ( '2013-W04' ) ;
993
1001
} ) ;
994
1002
@@ -1997,30 +2005,34 @@ describe('input', function() {
1997
2005
dealoc ( formElm ) ;
1998
2006
} ) ;
1999
2007
2000
- it ( 'should not reuse the hour part of a previous date object after changing the timezone' , function ( ) {
2008
+ it ( 'should not reuse the hours part of a previous date object after changing the timezone' , function ( ) {
2001
2009
var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2002
2010
2003
2011
helper . changeInputValueTo ( '2000-01-01' ) ;
2012
+ // The Date parser sets the hours part of the Date to 0 (00:00) (UTC)
2004
2013
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2005
2014
2006
2015
// Change the timezone offset so that the display date is a day earlier
2007
2016
// This does not change the model, but our implementation
2008
2017
// internally caches a Date object with this offset
2009
- // and re-uses it if part of the date changes
2018
+ // and re-uses it if part of the Date changes.
2019
+ // See https://github.com/angular/angular.js/commit/1a1ef62903c8fdf4ceb81277d966a8eff67f0a96
2010
2020
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
2011
2021
$rootScope . $apply ( function ( ) {
2012
2022
$rootScope . value = new Date ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2013
2023
} ) ;
2014
2024
expect ( inputElm . val ( ) ) . toBe ( '1999-12-31' ) ;
2015
2025
2016
- // Emptying the input should clear the cached date object
2017
- helper . changeInputValueTo ( '' ) ;
2018
-
2026
+ // At this point, the cached Date has its hours set to to 19 (00:00 - 05:00 = 19:00)
2019
2027
inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
2028
+
2029
+ // When changing the timezone back to UTC, the hours part of the Date should be set to
2030
+ // the default 0 (UTC) and not use the modified value of the cached Date object.
2020
2031
helper . changeInputValueTo ( '2000-01-01' ) ;
2021
2032
expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2022
2033
} ) ;
2023
2034
2035
+
2024
2036
describe ( 'min' , function ( ) {
2025
2037
2026
2038
it ( 'should invalidate' , function ( ) {
0 commit comments