@@ -662,6 +662,21 @@ describe('input', function() {
662
662
} ) ;
663
663
664
664
665
+ it ( 'should be possible to override the timezone' , function ( ) {
666
+ var inputElm = helper . compileInput ( '<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
667
+
668
+ helper . changeInputValueTo ( '2013-07' ) ;
669
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 6 , 1 ) ) ;
670
+
671
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
672
+
673
+ $rootScope . $apply ( function ( ) {
674
+ $rootScope . value = new Date ( Date . UTC ( 2014 , 6 , 1 ) ) ;
675
+ } ) ;
676
+ expect ( inputElm . val ( ) ) . toBe ( '2014-06' ) ;
677
+ } ) ;
678
+
679
+
665
680
they ( 'should use any timezone if specified in the options (format: $prop)' ,
666
681
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
667
682
function ( tz ) {
@@ -931,6 +946,21 @@ describe('input', function() {
931
946
} ) ;
932
947
933
948
949
+ it ( 'should be possible to override the timezone' , function ( ) {
950
+ var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
951
+
952
+ helper . changeInputValueTo ( '2013-W03' ) ;
953
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 0 , 17 ) ) ;
954
+
955
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+5000' } ) ;
956
+
957
+ $rootScope . $apply ( function ( ) {
958
+ $rootScope . value = new Date ( Date . UTC ( 2014 , 0 , 17 ) ) ;
959
+ } ) ;
960
+ expect ( inputElm . val ( ) ) . toBe ( '2014-W04' ) ;
961
+ } ) ;
962
+
963
+
934
964
they ( 'should use any timezone if specified in the options (format: $prop)' ,
935
965
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
936
966
function ( tz ) {
@@ -1137,6 +1167,25 @@ describe('input', function() {
1137
1167
} ) ;
1138
1168
1139
1169
1170
+ it ( 'should be possible to override the timezone' , function ( ) {
1171
+ var inputElm = helper . compileInput ( '<input type="datetime-local" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1172
+
1173
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1174
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1175
+
1176
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+0500' } ) ;
1177
+ $rootScope . $apply ( function ( ) {
1178
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 , 1 , 2 , 0 ) ) ;
1179
+ } ) ;
1180
+ expect ( inputElm . val ( ) ) . toBe ( '2001-01-01T06:02:00.000' ) ;
1181
+
1182
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1183
+
1184
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1185
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1186
+ } ) ;
1187
+
1188
+
1140
1189
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1141
1190
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1142
1191
function ( tz ) {
@@ -1482,6 +1531,25 @@ describe('input', function() {
1482
1531
} ) ;
1483
1532
1484
1533
1534
+ it ( 'should be possible to override the timezone' , function ( ) {
1535
+ var inputElm = helper . compileInput ( '<input type="time" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1536
+
1537
+ helper . changeInputValueTo ( '23:02:00' ) ;
1538
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1970 , 0 , 1 , 23 , 2 , 0 ) ) ;
1539
+
1540
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1541
+ $rootScope . $apply ( function ( ) {
1542
+ $rootScope . value = new Date ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1543
+ } ) ;
1544
+ expect ( inputElm . val ( ) ) . toBe ( '18:02:00.000' ) ;
1545
+
1546
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1547
+ helper . changeInputValueTo ( '23:02:00' ) ;
1548
+ // The year is still set from the previous date
1549
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1550
+ } ) ;
1551
+
1552
+
1485
1553
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1486
1554
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1487
1555
function ( tz ) {
@@ -1794,6 +1862,24 @@ describe('input', function() {
1794
1862
} ) ;
1795
1863
1796
1864
1865
+ it ( 'should be possible to override the timezone' , function ( ) {
1866
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1867
+
1868
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1869
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
1870
+
1871
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1872
+ $rootScope . $apply ( function ( ) {
1873
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
1874
+ } ) ;
1875
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
1876
+
1877
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1878
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1879
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 19 ) ) ;
1880
+ } ) ;
1881
+
1882
+
1797
1883
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1798
1884
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1799
1885
function ( tz ) {
@@ -1879,6 +1965,30 @@ describe('input', function() {
1879
1965
dealoc ( formElm ) ;
1880
1966
} ) ;
1881
1967
1968
+ it ( 'should not reuse the hour part of a previous date object after emptying the input' , function ( ) {
1969
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1970
+
1971
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1972
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
1973
+
1974
+ // Change the timezone offset so that the display date is a day earlier
1975
+ // This does not change the model, but our implementation
1976
+ // internally caches a Date object with this offset
1977
+ // and re-uses it if part of the date changes
1978
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1979
+ $rootScope . $apply ( function ( ) {
1980
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
1981
+ } ) ;
1982
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
1983
+
1984
+ // Emptying the input should clear the cached date object
1985
+ helper . changeInputValueTo ( '' ) ;
1986
+
1987
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1988
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1989
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
1990
+ } ) ;
1991
+
1882
1992
describe ( 'min' , function ( ) {
1883
1993
1884
1994
it ( 'should invalidate' , function ( ) {
0 commit comments