Skip to content

Commit ccdb700

Browse files
committed
fix(input): take timezone into account when validating minimum and maximum date spans.
Closes angular#16342 Closes angular#16390
1 parent 88cb9af commit ccdb700

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/ng/directive/input.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1440,11 +1440,7 @@ function createDateInputType(type, regexp, parseDate, format) {
14401440
// Note: We cannot read ctrl.$modelValue, as there might be a different
14411441
// parser/formatter in the processing chain so that the model
14421442
// contains some different data format!
1443-
var parsedDate = parseDate(value, previousDate);
1444-
if (timezone) {
1445-
parsedDate = convertTimezoneToLocal(parsedDate, timezone);
1446-
}
1447-
return parsedDate;
1443+
return parseDateAndConvertTimeZoneToLocal(value, previousDate);
14481444
}
14491445
ctrl.$$parserName = type;
14501446
return undefined;
@@ -1494,7 +1490,15 @@ function createDateInputType(type, regexp, parseDate, format) {
14941490
}
14951491

14961492
function parseObservedDateValue(val) {
1497-
return isDefined(val) && !isDate(val) ? parseDate(val) || undefined : val;
1493+
return isDefined(val) && !isDate(val) ? parseDateAndConvertTimeZoneToLocal(val) || undefined : val;
1494+
}
1495+
1496+
function parseDateAndConvertTimeZoneToLocal(value, previousDate) {
1497+
var parsedDate = previousDate ? parseDate(value, previousDate) : parseDate(value);
1498+
if (timezone) {
1499+
parsedDate = convertTimezoneToLocal(parsedDate, timezone);
1500+
}
1501+
return parsedDate;
14981502
}
14991503
};
15001504
}

test/ng/directive/inputSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,16 @@ describe('input', function() {
840840

841841
expect($rootScope.form.alias.$error.max).toBeFalsy();
842842
});
843+
844+
it('should validate when timezone is provided.', function() {
845+
inputElm = helper.compileInput('<input type="date" ng-model="value" name="alias" ' +
846+
'min="2013-01-01" max="2013-12-31" ng-model-options="{timezone: \'UTC\', allowInvalid: true}" required/>');
847+
$rootScope.value = new Date(Date.UTC(2013, 11, 31));
848+
$rootScope.$digest();
849+
850+
expect($rootScope.form.alias.$error.max).toBeFalsy();
851+
expect($rootScope.form.alias.$valid).toBeTruthy();
852+
});
843853
});
844854
});
845855

0 commit comments

Comments
 (0)