@@ -113,6 +113,9 @@ var inputType = {
113
113
* modern browsers do not yet support this input type, it is important to provide cues to users on the
114
114
* expected input format via a placeholder or label. The model must always be a Date object.
115
115
*
116
+ * The timezone to be used to read/write the `Date` instance in the model can be defined using
117
+ * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
118
+ *
116
119
* @param {string } ngModel Assignable angular expression to data-bind to.
117
120
* @param {string= } name Property name of the form under which the control is published.
118
121
* @param {string= } min Sets the `min` validation error key if the value entered is less than `min`. This must be a
@@ -198,6 +201,9 @@ var inputType = {
198
201
* the HTML5 date input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
199
202
* local datetime format (yyyy-MM-ddTHH:mm), for example: `2010-12-28T14:57`. The model must be a Date object.
200
203
*
204
+ * The timezone to be used to read/write the `Date` instance in the model can be defined using
205
+ * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
206
+ *
201
207
* @param {string } ngModel Assignable angular expression to data-bind to.
202
208
* @param {string= } name Property name of the form under which the control is published.
203
209
* @param {string= } min Sets the `min` validation error key if the value entered is less than `min`. This must be a
@@ -284,6 +290,9 @@ var inputType = {
284
290
* local time format (HH:mm), for example: `14:57`. Model must be a Date object. This binding will always output a
285
291
* Date object to the model of January 1, 1970, or local date `new Date(1970, 0, 1, HH, mm)`.
286
292
*
293
+ * The timezone to be used to read/write the `Date` instance in the model can be defined using
294
+ * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
295
+ *
287
296
* @param {string } ngModel Assignable angular expression to data-bind to.
288
297
* @param {string= } name Property name of the form under which the control is published.
289
298
* @param {string= } min Sets the `min` validation error key if the value entered is less than `min`. This must be a
@@ -369,6 +378,9 @@ var inputType = {
369
378
* the HTML5 week input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
370
379
* week format (yyyy-W##), for example: `2013-W02`. The model must always be a Date object.
371
380
*
381
+ * The timezone to be used to read/write the `Date` instance in the model can be defined using
382
+ * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
383
+ *
372
384
* @param {string } ngModel Assignable angular expression to data-bind to.
373
385
* @param {string= } name Property name of the form under which the control is published.
374
386
* @param {string= } min Sets the `min` validation error key if the value entered is less than `min`. This must be a
@@ -453,6 +465,9 @@ var inputType = {
453
465
* month format (yyyy-MM), for example: `2009-01`. The model must always be a Date object. In the event the model is
454
466
* not set to the first of the month, the first of that model's month is assumed.
455
467
*
468
+ * The timezone to be used to read/write the `Date` instance in the model can be defined using
469
+ * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
470
+ *
456
471
* @param {string } ngModel Assignable angular expression to data-bind to.
457
472
* @param {string= } name Property name of the form under which the control is published.
458
473
* @param {string= } min Sets the `min` validation error key if the value entered is less than `min`. This must be
@@ -1061,6 +1076,7 @@ function createDateParser(regexp, mapping) {
1061
1076
function createDateInputType ( type , regexp , parseDate , format ) {
1062
1077
return function dynamicDateInputType ( scope , element , attr , ctrl , $sniffer , $browser , $filter ) {
1063
1078
textInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1079
+ var timezone = ctrl && ctrl . $options && ctrl . $options . timezone ;
1064
1080
1065
1081
ctrl . $parsers . push ( function ( value ) {
1066
1082
if ( ctrl . $isEmpty ( value ) ) {
@@ -1070,7 +1086,11 @@ function createDateInputType(type, regexp, parseDate, format) {
1070
1086
1071
1087
if ( regexp . test ( value ) ) {
1072
1088
ctrl . $setValidity ( type , true ) ;
1073
- return parseDate ( value ) ;
1089
+ var parsedDate = parseDate ( value ) ;
1090
+ if ( timezone === 'UTC' ) {
1091
+ parsedDate . setMinutes ( parsedDate . getMinutes ( ) - parsedDate . getTimezoneOffset ( ) ) ;
1092
+ }
1093
+ return parsedDate ;
1074
1094
}
1075
1095
1076
1096
ctrl . $setValidity ( type , false ) ;
@@ -1079,7 +1099,7 @@ function createDateInputType(type, regexp, parseDate, format) {
1079
1099
1080
1100
ctrl . $formatters . push ( function ( value ) {
1081
1101
if ( isDate ( value ) ) {
1082
- return $filter ( 'date' ) ( value , format ) ;
1102
+ return $filter ( 'date' ) ( value , format , timezone ) ;
1083
1103
}
1084
1104
return '' ;
1085
1105
} ) ;
@@ -2604,6 +2624,9 @@ var ngValueDirective = function() {
2604
2624
* `ngModelOptions="{ updateOn: 'default blur', debounce: {'default': 500, 'blur': 0} }"`
2605
2625
* - `getterSetter`: boolean value which determines whether or not to treat functions bound to
2606
2626
`ngModel` as getters/setters.
2627
+ * - `timezone`: Defines the timezone to be used to read/write the `Date` instance in the model for
2628
+ * `<input type="date">`, `<input type="time">`, ... . Right now, the only supported value is `'UTC'`,
2629
+ * otherwise the default timezone of the browser will be used.
2607
2630
*
2608
2631
* @example
2609
2632
0 commit comments