diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js
index 228f5fb2366a..b0bdbb10bfea 100644
--- a/src/ng/directive/input.js
+++ b/src/ng/directive/input.js
@@ -1440,11 +1440,7 @@ function createDateInputType(type, regexp, parseDate, format) {
// Note: We cannot read ctrl.$modelValue, as there might be a different
// parser/formatter in the processing chain so that the model
// contains some different data format!
- var parsedDate = parseDate(value, previousDate);
- if (timezone) {
- parsedDate = convertTimezoneToLocal(parsedDate, timezone);
- }
- return parsedDate;
+ return parseDateAndConvertTimeZoneToLocal(value, previousDate);
}
ctrl.$$parserName = type;
return undefined;
@@ -1494,7 +1490,15 @@ function createDateInputType(type, regexp, parseDate, format) {
}
function parseObservedDateValue(val) {
- return isDefined(val) && !isDate(val) ? parseDate(val) || undefined : val;
+ return isDefined(val) && !isDate(val) ? parseDateAndConvertTimeZoneToLocal(val) || undefined : val;
+ }
+
+ function parseDateAndConvertTimeZoneToLocal(value, previousDate) {
+ var parsedDate = parseDate(value, previousDate);
+ if (!isNaN(parsedDate) && timezone) {
+ parsedDate = convertTimezoneToLocal(parsedDate, timezone);
+ }
+ return parsedDate;
}
};
}
diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js
index 9c58807345d3..46be295cc8a8 100644
--- a/test/ng/directive/inputSpec.js
+++ b/test/ng/directive/inputSpec.js
@@ -840,6 +840,23 @@ describe('input', function() {
expect($rootScope.form.alias.$error.max).toBeFalsy();
});
+
+ it('should validate when timezone is provided.', function() {
+ inputElm = helper.compileInput('');
+ $rootScope.maxVal = '2013-01';
+ $rootScope.value = new Date(Date.UTC(2013, 0, 1, 0, 0, 0));
+ $rootScope.$digest();
+
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+
+ $rootScope.value = '';
+ helper.changeInputValueTo('2013-01');
+ expect(inputElm).toBeValid();
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+ });
});
});
@@ -1073,6 +1090,25 @@ describe('input', function() {
expect($rootScope.form.alias.$error.max).toBeFalsy();
});
+
+ it('should validate when timezone is provided.', function() {
+ inputElm = helper.compileInput('');
+ // The calendar week comparison date is January 17. Setting the timezone to -2400
+ // makes the January 18 date value valid.
+ $rootScope.maxVal = '2013-W03';
+ $rootScope.value = new Date(Date.UTC(2013, 0, 18));
+ $rootScope.$digest();
+
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+
+ $rootScope.value = '';
+ helper.changeInputValueTo('2013-W03');
+ expect(inputElm).toBeValid();
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+ });
});
});
@@ -1342,6 +1378,23 @@ describe('input', function() {
expect($rootScope.form.alias.$error.max).toBeFalsy();
});
+
+ it('should validate when timezone is provided.', function() {
+ inputElm = helper.compileInput('');
+ $rootScope.maxVal = '2013-01-01T00:00:00';
+ $rootScope.value = new Date(Date.UTC(2013, 0, 1, 0, 0, 0));
+ $rootScope.$digest();
+
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+
+ $rootScope.value = '';
+ helper.changeInputValueTo('2013-01-01T00:00:00');
+ expect(inputElm).toBeValid();
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+ });
});
@@ -1660,6 +1713,23 @@ describe('input', function() {
expect($rootScope.form.alias.$error.max).toBeFalsy();
});
+
+ it('should validate when timezone is provided.', function() {
+ inputElm = helper.compileInput('');
+ $rootScope.maxVal = '22:30:00';
+ $rootScope.value = new Date(Date.UTC(1970, 0, 1, 22, 30, 0));
+ $rootScope.$digest();
+
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+
+ $rootScope.value = '';
+ helper.changeInputValueTo('22:30:00');
+ expect(inputElm).toBeValid();
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+ });
});
@@ -2005,6 +2075,24 @@ describe('input', function() {
expect($rootScope.form.alias.$error.max).toBeFalsy();
});
+
+ it('should validate when timezone is provided.', function() {
+ var inputElm = helper.compileInput('');
+
+ $rootScope.maxVal = '2013-12-01';
+ $rootScope.value = new Date(Date.UTC(2013, 11, 1, 0, 0, 0));
+ $rootScope.$digest();
+
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+
+ $rootScope.value = '';
+ helper.changeInputValueTo('2013-12-01');
+ expect(inputElm).toBeValid();
+ expect($rootScope.form.alias.$error.max).toBeFalsy();
+ expect($rootScope.form.alias.$valid).toBeTruthy();
+ });
});