Skip to content

Commit ab4580f

Browse files
committed
fix(datepicker): *BREAKING CHANGE* remove new Date fallback
- Remove `new Date` fallback due to buggy behavior Closes angular-ui#2513 Closes angular-ui#3294 Closes angular-ui#3344 Closes angular-ui#3682 Closes angular-ui#4092 Fixes angular-ui#1289 Fixes angular-ui#2446 Fixes angular-ui#3037 Fixes angular-ui#3104 Fixes angular-ui#3196 Fixes angular-ui#3206 Fixes angular-ui#3342 Fixes angular-ui#3617 Fixes angular-ui#3644
1 parent 2004757 commit ab4580f

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/datepicker/datepicker.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
602602
} else if (angular.isDate(viewValue) && !isNaN(viewValue)) {
603603
return viewValue;
604604
} else if (angular.isString(viewValue)) {
605-
var date = dateParser.parse(viewValue, dateFormat, scope.date) || new Date(viewValue);
605+
var date = dateParser.parse(viewValue, dateFormat, scope.date);
606606
if (isNaN(date)) {
607607
return undefined;
608608
} else {
@@ -628,7 +628,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
628628
} else if (angular.isDate(value) && !isNaN(value)) {
629629
return true;
630630
} else if (angular.isString(value)) {
631-
var date = dateParser.parse(value, dateFormat) || new Date(value);
631+
var date = dateParser.parse(value, dateFormat);
632632
return !isNaN(date);
633633
} else {
634634
return false;
@@ -669,7 +669,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
669669

670670
// Detect changes in the view from the text box
671671
ngModel.$viewChangeListeners.push(function () {
672-
scope.date = dateParser.parse(ngModel.$viewValue, dateFormat, scope.date) || new Date(ngModel.$viewValue);
672+
scope.date = dateParser.parse(ngModel.$viewValue, dateFormat, scope.date);
673673
});
674674

675675
var documentClickBind = function(event) {

src/datepicker/test/datepicker.spec.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1276,21 +1276,21 @@ describe('datepicker directive', function () {
12761276
});
12771277

12781278
it('updates the model & calendar when input value changes', function() {
1279-
changeInputValueTo(inputEl, 'March 5, 1980');
1279+
changeInputValueTo(inputEl, '2010-09-15');
12801280

1281-
expect($rootScope.date.getFullYear()).toEqual(1980);
1282-
expect($rootScope.date.getMonth()).toEqual(2);
1283-
expect($rootScope.date.getDate()).toEqual(5);
1281+
expect($rootScope.date.getFullYear()).toEqual(2010);
1282+
expect($rootScope.date.getMonth()).toEqual(8);
1283+
expect($rootScope.date.getDate()).toEqual(15);
12841284

12851285
expect(getOptions(true)).toEqual([
1286-
['24', '25', '26', '27', '28', '29', '01'],
1287-
['02', '03', '04', '05', '06', '07', '08'],
1288-
['09', '10', '11', '12', '13', '14', '15'],
1289-
['16', '17', '18', '19', '20', '21', '22'],
1290-
['23', '24', '25', '26', '27', '28', '29'],
1291-
['30', '31', '01', '02', '03', '04', '05']
1286+
['29', '30', '31', '01', '02', '03', '04'],
1287+
['05', '06', '07', '08', '09', '10', '11'],
1288+
['12', '13', '14', '15', '16', '17', '18'],
1289+
['19', '20', '21', '22', '23', '24', '25'],
1290+
['26', '27', '28', '29', '30', '01', '02'],
1291+
['03', '04', '05', '06', '07', '08', '09']
12921292
]);
1293-
expectSelectedElement( 10 );
1293+
expectSelectedElement( 17 );
12941294
});
12951295

12961296
it('closes when click outside of calendar', function() {
@@ -1389,7 +1389,7 @@ describe('datepicker directive', function () {
13891389
}));
13901390

13911391
it('should change model and update calendar after debounce timeout', function() {
1392-
changeInputValueTo(inputEl, 'March 5, 1980');
1392+
changeInputValueTo(inputEl, '1980-03-05');
13931393

13941394
expect($rootScope.date.getFullYear()).toEqual(2010);
13951395
expect($rootScope.date.getMonth()).toEqual(9 - 1);

0 commit comments

Comments
 (0)