@@ -718,6 +718,21 @@ describe('input', function() {
718
718
} ) ;
719
719
720
720
721
+ it ( 'should be possible to override the timezone' , function ( ) {
722
+ var inputElm = helper . compileInput ( '<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
723
+
724
+ helper . changeInputValueTo ( '2013-07' ) ;
725
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 6 , 1 ) ) ;
726
+
727
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
728
+
729
+ $rootScope . $apply ( function ( ) {
730
+ $rootScope . value = new Date ( Date . UTC ( 2014 , 6 , 1 ) ) ;
731
+ } ) ;
732
+ expect ( inputElm . val ( ) ) . toBe ( '2014-06' ) ;
733
+ } ) ;
734
+
735
+
721
736
they ( 'should use any timezone if specified in the options (format: $prop)' ,
722
737
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
723
738
function ( tz ) {
@@ -1004,6 +1019,21 @@ describe('input', function() {
1004
1019
} ) ;
1005
1020
1006
1021
1022
+ it ( 'should be possible to override the timezone' , function ( ) {
1023
+ var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1024
+
1025
+ helper . changeInputValueTo ( '2013-W03' ) ;
1026
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 0 , 17 ) ) ;
1027
+
1028
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+5000' } ) ;
1029
+
1030
+ $rootScope . $apply ( function ( ) {
1031
+ $rootScope . value = new Date ( Date . UTC ( 2014 , 0 , 17 ) ) ;
1032
+ } ) ;
1033
+ expect ( inputElm . val ( ) ) . toBe ( '2014-W04' ) ;
1034
+ } ) ;
1035
+
1036
+
1007
1037
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1008
1038
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1009
1039
function ( tz ) {
@@ -1229,6 +1259,25 @@ describe('input', function() {
1229
1259
} ) ;
1230
1260
1231
1261
1262
+ it ( 'should be possible to override the timezone' , function ( ) {
1263
+ var inputElm = helper . compileInput ( '<input type="datetime-local" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1264
+
1265
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1266
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1267
+
1268
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+0500' } ) ;
1269
+ $rootScope . $apply ( function ( ) {
1270
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 , 1 , 2 , 0 ) ) ;
1271
+ } ) ;
1272
+ expect ( inputElm . val ( ) ) . toBe ( '2001-01-01T06:02:00.000' ) ;
1273
+
1274
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1275
+
1276
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1277
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1278
+ } ) ;
1279
+
1280
+
1232
1281
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1233
1282
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1234
1283
function ( tz ) {
@@ -1591,6 +1640,25 @@ describe('input', function() {
1591
1640
} ) ;
1592
1641
1593
1642
1643
+ it ( 'should be possible to override the timezone' , function ( ) {
1644
+ var inputElm = helper . compileInput ( '<input type="time" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1645
+
1646
+ helper . changeInputValueTo ( '23:02:00' ) ;
1647
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1970 , 0 , 1 , 23 , 2 , 0 ) ) ;
1648
+
1649
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1650
+ $rootScope . $apply ( function ( ) {
1651
+ $rootScope . value = new Date ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1652
+ } ) ;
1653
+ expect ( inputElm . val ( ) ) . toBe ( '18:02:00.000' ) ;
1654
+
1655
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1656
+ helper . changeInputValueTo ( '23:02:00' ) ;
1657
+ // The year is still set from the previous date
1658
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1659
+ } ) ;
1660
+
1661
+
1594
1662
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1595
1663
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1596
1664
function ( tz ) {
@@ -1920,6 +1988,24 @@ describe('input', function() {
1920
1988
} ) ;
1921
1989
1922
1990
1991
+ it ( 'should be possible to override the timezone' , function ( ) {
1992
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1993
+
1994
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1995
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
1996
+
1997
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1998
+ $rootScope . $apply ( function ( ) {
1999
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
2000
+ } ) ;
2001
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
2002
+
2003
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
2004
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2005
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 19 ) ) ;
2006
+ } ) ;
2007
+
2008
+
1923
2009
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1924
2010
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1925
2011
function ( tz ) {
@@ -2005,6 +2091,30 @@ describe('input', function() {
2005
2091
dealoc ( formElm ) ;
2006
2092
} ) ;
2007
2093
2094
+ it ( 'should not reuse the hour part of a previous date object after emptying the input' , function ( ) {
2095
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2096
+
2097
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2098
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
2099
+
2100
+ // Change the timezone offset so that the display date is a day earlier
2101
+ // This does not change the model, but our implementation
2102
+ // internally caches a Date object with this offset
2103
+ // and re-uses it if part of the date changes
2104
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
2105
+ $rootScope . $apply ( function ( ) {
2106
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
2107
+ } ) ;
2108
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
2109
+
2110
+ // Emptying the input should clear the cached date object
2111
+ helper . changeInputValueTo ( '' ) ;
2112
+
2113
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
2114
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2115
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2116
+ } ) ;
2117
+
2008
2118
describe ( 'min' , function ( ) {
2009
2119
2010
2120
it ( 'should invalidate' , function ( ) {
0 commit comments