@@ -688,6 +688,21 @@ describe('input', function() {
688
688
} ) ;
689
689
690
690
691
+ it ( 'should be possible to override the timezone' , function ( ) {
692
+ var inputElm = helper . compileInput ( '<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
693
+
694
+ helper . changeInputValueTo ( '2013-07' ) ;
695
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 6 , 1 ) ) ;
696
+
697
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
698
+
699
+ $rootScope . $apply ( function ( ) {
700
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 6 , 1 ) ) ;
701
+ } ) ;
702
+ expect ( inputElm . val ( ) ) . toBe ( '2013-06' ) ;
703
+ } ) ;
704
+
705
+
691
706
they ( 'should use any timezone if specified in the options (format: $prop)' ,
692
707
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
693
708
function ( tz ) {
@@ -974,6 +989,30 @@ describe('input', function() {
974
989
} ) ;
975
990
976
991
992
+ it ( 'should be possible to override the timezone' , function ( ) {
993
+ var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
994
+
995
+ // January 19 2013 is a Saturday
996
+ $rootScope . $apply ( function ( ) {
997
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
998
+ } ) ;
999
+
1000
+ expect ( inputElm . val ( ) ) . toBe ( '2013-W03' ) ;
1001
+
1002
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+2400' } ) ;
1003
+
1004
+ // To check that the timezone overwrite works, apply an offset of +24 hours.
1005
+ // Since January 19 is a Saturday, +24 will turn the formatted Date into January 20 - Sunday -
1006
+ // which is in calendar week 4 instead of 3.
1007
+ $rootScope . $apply ( function ( ) {
1008
+ $rootScope . value = new Date ( Date . UTC ( 2013 , 0 , 19 ) ) ;
1009
+ } ) ;
1010
+
1011
+ // Verifying that the displayed week is week 4 confirms that overriding the timezone worked
1012
+ expect ( inputElm . val ( ) ) . toBe ( '2013-W04' ) ;
1013
+ } ) ;
1014
+
1015
+
977
1016
they ( 'should use any timezone if specified in the options (format: $prop)' ,
978
1017
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
979
1018
function ( tz ) {
@@ -1199,6 +1238,25 @@ describe('input', function() {
1199
1238
} ) ;
1200
1239
1201
1240
1241
+ it ( 'should be possible to override the timezone' , function ( ) {
1242
+ var inputElm = helper . compileInput ( '<input type="datetime-local" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1243
+
1244
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1245
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1246
+
1247
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+0500' } ) ;
1248
+ $rootScope . $apply ( function ( ) {
1249
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 , 1 , 2 , 0 ) ) ;
1250
+ } ) ;
1251
+ expect ( inputElm . val ( ) ) . toBe ( '2001-01-01T06:02:00.000' ) ;
1252
+
1253
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1254
+
1255
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1256
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1257
+ } ) ;
1258
+
1259
+
1202
1260
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1203
1261
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1204
1262
function ( tz ) {
@@ -1561,6 +1619,25 @@ describe('input', function() {
1561
1619
} ) ;
1562
1620
1563
1621
1622
+ it ( 'should be possible to override the timezone' , function ( ) {
1623
+ var inputElm = helper . compileInput ( '<input type="time" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1624
+
1625
+ helper . changeInputValueTo ( '23:02:00' ) ;
1626
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1970 , 0 , 1 , 23 , 2 , 0 ) ) ;
1627
+
1628
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1629
+ $rootScope . $apply ( function ( ) {
1630
+ $rootScope . value = new Date ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1631
+ } ) ;
1632
+ expect ( inputElm . val ( ) ) . toBe ( '18:02:00.000' ) ;
1633
+
1634
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1635
+ helper . changeInputValueTo ( '23:02:00' ) ;
1636
+ // The year is still set from the previous date
1637
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1638
+ } ) ;
1639
+
1640
+
1564
1641
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1565
1642
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1566
1643
function ( tz ) {
@@ -1890,6 +1967,24 @@ describe('input', function() {
1890
1967
} ) ;
1891
1968
1892
1969
1970
+ it ( 'should be possible to override the timezone' , function ( ) {
1971
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1972
+
1973
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1974
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
1975
+
1976
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1977
+ $rootScope . $apply ( function ( ) {
1978
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
1979
+ } ) ;
1980
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
1981
+
1982
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1983
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1984
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1985
+ } ) ;
1986
+
1987
+
1893
1988
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1894
1989
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1895
1990
function ( tz ) {
@@ -1975,6 +2070,34 @@ describe('input', function() {
1975
2070
dealoc ( formElm ) ;
1976
2071
} ) ;
1977
2072
2073
+ it ( 'should not reuse the hours part of a previous date object after changing the timezone' , function ( ) {
2074
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2075
+
2076
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2077
+ // The Date parser sets the hours part of the Date to 0 (00:00) (UTC)
2078
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2079
+
2080
+ // Change the timezone offset so that the display date is a day earlier
2081
+ // This does not change the model, but our implementation
2082
+ // internally caches a Date object with this offset
2083
+ // and re-uses it if part of the Date changes.
2084
+ // See https://github.com/angular/angular.js/commit/1a1ef62903c8fdf4ceb81277d966a8eff67f0a96
2085
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
2086
+ $rootScope . $apply ( function ( ) {
2087
+ $rootScope . value = new Date ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2088
+ } ) ;
2089
+ expect ( inputElm . val ( ) ) . toBe ( '1999-12-31' ) ;
2090
+
2091
+ // At this point, the cached Date has its hours set to to 19 (00:00 - 05:00 = 19:00)
2092
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
2093
+
2094
+ // When changing the timezone back to UTC, the hours part of the Date should be set to
2095
+ // the default 0 (UTC) and not use the modified value of the cached Date object.
2096
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2097
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2098
+ } ) ;
2099
+
2100
+
1978
2101
describe ( 'min' , function ( ) {
1979
2102
1980
2103
it ( 'should invalidate' , function ( ) {
0 commit comments