Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 29f0b56

Browse files
committed
fix(input): use year 1970 instead of 1900 for input[time]
BREAKING CHANGE: According to the HTML5 spec `input[time]` should create dates based on the year 1970 (used to be based on the year 1900). Related to #8447.
1 parent 4739b1d commit 29f0b56

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/ng/directive/input.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ var inputType = {
282282
* Input with time validation and transformation. In browsers that do not yet support
283283
* the HTML5 date input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
284284
* local time format (HH:mm), for example: `14:57`. Model must be a Date object. This binding will always output a
285-
* Date object to the model of January 1, 1900, or local date `new Date(0, 0, 1, HH, mm)`.
285+
* Date object to the model of January 1, 1970, or local date `new Date(1970, 0, 1, HH, mm)`.
286286
*
287287
* @param {string} ngModel Assignable angular expression to data-bind to.
288288
* @param {string=} name Property name of the form under which the control is published.
@@ -303,7 +303,7 @@ var inputType = {
303303
<script>
304304
angular.module('timeExample', [])
305305
.controller('DateController', ['$scope', function($scope) {
306-
$scope.value = new Date(0, 0, 1, 14, 57);
306+
$scope.value = new Date(1970, 0, 1, 14, 57);
307307
}]);
308308
</script>
309309
<form name="myForm" ng-controller="DateController as dateCtrl">
@@ -1042,7 +1042,7 @@ function createDateParser(regexp, mapping) {
10421042

10431043
if(parts) {
10441044
parts.shift();
1045-
map = { yyyy: 0, MM: 1, dd: 1, HH: 0, mm: 0 };
1045+
map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0 };
10461046

10471047
forEach(parts, function(part, index) {
10481048
if(index < mapping.length) {

test/ng/directive/inputSpec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@ describe('input', function() {
19471947
compileInput('<input type="time" ng-model="threeFortyOnePm"/>');
19481948

19491949
scope.$apply(function (){
1950-
scope.threeFortyOnePm = new Date(0, 0, 1, 15, 41);
1950+
scope.threeFortyOnePm = new Date(1970, 0, 1, 15, 41);
19511951
});
19521952

19531953
expect(inputElm.val()).toBe('15:41');
@@ -1957,7 +1957,7 @@ describe('input', function() {
19571957
compileInput('<input type="time" ng-model="breakMe"/>');
19581958

19591959
scope.$apply(function (){
1960-
scope.breakMe = new Date(0, 0, 1, 16, 25);
1960+
scope.breakMe = new Date(1970, 0, 1, 16, 25);
19611961
});
19621962

19631963
expect(inputElm.val()).toBe('16:25');
@@ -2023,7 +2023,7 @@ describe('input', function() {
20232023
it('should validate', function (){
20242024
changeInputValueTo('23:02');
20252025
expect(inputElm).toBeValid();
2026-
expect(+scope.value).toBe(+new Date(0, 0, 1, 23, 2));
2026+
expect(+scope.value).toBe(+new Date(1970, 0, 1, 23, 2));
20272027
expect(scope.form.alias.$error.min).toBeFalsy();
20282028
});
20292029
});
@@ -2043,7 +2043,7 @@ describe('input', function() {
20432043
it('should validate', function() {
20442044
changeInputValueTo('05:30');
20452045
expect(inputElm).toBeValid();
2046-
expect(+scope.value).toBe(+new Date(0, 0, 1, 5, 30));
2046+
expect(+scope.value).toBe(+new Date(1970, 0, 1, 5, 30));
20472047
expect(scope.form.alias.$error.max).toBeFalsy();
20482048
});
20492049
});

0 commit comments

Comments
 (0)