@@ -693,6 +693,21 @@ describe('input', function() {
693
693
} ) ;
694
694
695
695
696
+ it ( 'should be possible to override the timezone' , function ( ) {
697
+ var inputElm = helper . compileInput ( '<input type="month" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
698
+
699
+ helper . changeInputValueTo ( '2013-07' ) ;
700
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 6 , 1 ) ) ;
701
+
702
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
703
+
704
+ $rootScope . $apply ( function ( ) {
705
+ $rootScope . value = new Date ( Date . UTC ( 2014 , 6 , 1 ) ) ;
706
+ } ) ;
707
+ expect ( inputElm . val ( ) ) . toBe ( '2014-06' ) ;
708
+ } ) ;
709
+
710
+
696
711
they ( 'should use any timezone if specified in the options (format: $prop)' ,
697
712
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
698
713
function ( tz ) {
@@ -962,6 +977,21 @@ describe('input', function() {
962
977
} ) ;
963
978
964
979
980
+ it ( 'should be possible to override the timezone' , function ( ) {
981
+ var inputElm = helper . compileInput ( '<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
982
+
983
+ helper . changeInputValueTo ( '2013-W03' ) ;
984
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2013 , 0 , 17 ) ) ;
985
+
986
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+5000' } ) ;
987
+
988
+ $rootScope . $apply ( function ( ) {
989
+ $rootScope . value = new Date ( Date . UTC ( 2014 , 0 , 17 ) ) ;
990
+ } ) ;
991
+ expect ( inputElm . val ( ) ) . toBe ( '2014-W04' ) ;
992
+ } ) ;
993
+
994
+
965
995
they ( 'should use any timezone if specified in the options (format: $prop)' ,
966
996
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
967
997
function ( tz ) {
@@ -1168,6 +1198,25 @@ describe('input', function() {
1168
1198
} ) ;
1169
1199
1170
1200
1201
+ it ( 'should be possible to override the timezone' , function ( ) {
1202
+ var inputElm = helper . compileInput ( '<input type="datetime-local" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1203
+
1204
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1205
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1206
+
1207
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '+0500' } ) ;
1208
+ $rootScope . $apply ( function ( ) {
1209
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 , 1 , 2 , 0 ) ) ;
1210
+ } ) ;
1211
+ expect ( inputElm . val ( ) ) . toBe ( '2001-01-01T06:02:00.000' ) ;
1212
+
1213
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1214
+
1215
+ helper . changeInputValueTo ( '2000-01-01T01:02' ) ;
1216
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
1217
+ } ) ;
1218
+
1219
+
1171
1220
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1172
1221
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1173
1222
function ( tz ) {
@@ -1513,6 +1562,25 @@ describe('input', function() {
1513
1562
} ) ;
1514
1563
1515
1564
1565
+ it ( 'should be possible to override the timezone' , function ( ) {
1566
+ var inputElm = helper . compileInput ( '<input type="time" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1567
+
1568
+ helper . changeInputValueTo ( '23:02:00' ) ;
1569
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1970 , 0 , 1 , 23 , 2 , 0 ) ) ;
1570
+
1571
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1572
+ $rootScope . $apply ( function ( ) {
1573
+ $rootScope . value = new Date ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1574
+ } ) ;
1575
+ expect ( inputElm . val ( ) ) . toBe ( '18:02:00.000' ) ;
1576
+
1577
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1578
+ helper . changeInputValueTo ( '23:02:00' ) ;
1579
+ // The year is still set from the previous date
1580
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 1971 , 0 , 1 , 23 , 2 , 0 ) ) ;
1581
+ } ) ;
1582
+
1583
+
1516
1584
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1517
1585
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1518
1586
function ( tz ) {
@@ -1825,6 +1893,24 @@ describe('input', function() {
1825
1893
} ) ;
1826
1894
1827
1895
1896
+ it ( 'should be possible to override the timezone' , function ( ) {
1897
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
1898
+
1899
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1900
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
1901
+
1902
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
1903
+ $rootScope . $apply ( function ( ) {
1904
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
1905
+ } ) ;
1906
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
1907
+
1908
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
1909
+ helper . changeInputValueTo ( '2000-01-01' ) ;
1910
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 19 ) ) ;
1911
+ } ) ;
1912
+
1913
+
1828
1914
they ( 'should use any timezone if specified in the options (format: $prop)' ,
1829
1915
{ '+HHmm' : '+0500' , '+HH:mm' : '+05:00' } ,
1830
1916
function ( tz ) {
@@ -1910,6 +1996,30 @@ describe('input', function() {
1910
1996
dealoc ( formElm ) ;
1911
1997
} ) ;
1912
1998
1999
+ it ( 'should not reuse the hour part of a previous date object after emptying the input' , function ( ) {
2000
+ var inputElm = helper . compileInput ( '<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />' ) ;
2001
+
2002
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2003
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 ) ) ;
2004
+
2005
+ // Change the timezone offset so that the display date is a day earlier
2006
+ // This does not change the model, but our implementation
2007
+ // internally caches a Date object with this offset
2008
+ // and re-uses it if part of the date changes
2009
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : '-0500' } ) ;
2010
+ $rootScope . $apply ( function ( ) {
2011
+ $rootScope . value = new Date ( Date . UTC ( 2001 , 0 , 1 ) ) ;
2012
+ } ) ;
2013
+ expect ( inputElm . val ( ) ) . toBe ( '2000-12-31' ) ;
2014
+
2015
+ // Emptying the input should clear the cached date object
2016
+ helper . changeInputValueTo ( '' ) ;
2017
+
2018
+ inputElm . controller ( 'ngModel' ) . $overrideModelOptions ( { timezone : 'UTC' } ) ;
2019
+ helper . changeInputValueTo ( '2000-01-01' ) ;
2020
+ expect ( + $rootScope . value ) . toBe ( Date . UTC ( 2000 , 0 , 1 , 0 ) ) ;
2021
+ } ) ;
2022
+
1913
2023
describe ( 'min' , function ( ) {
1914
2024
1915
2025
it ( 'should invalidate' , function ( ) {
0 commit comments