From ab4580fd81582cde5fd869c87cc4366cdc7f534d Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Fri, 31 Jul 2015 22:45:55 -0700 Subject: [PATCH] fix(datepicker): *BREAKING CHANGE* remove `new Date` fallback - Remove `new Date` fallback due to buggy behavior Closes #2513 Closes #3294 Closes #3344 Closes #3682 Closes #4092 Fixes #1289 Fixes #2446 Fixes #3037 Fixes #3104 Fixes #3196 Fixes #3206 Fixes #3342 Fixes #3617 Fixes #3644 --- src/datepicker/datepicker.js | 6 +++--- src/datepicker/test/datepicker.spec.js | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 7fc5cc3ab4..64febd4c17 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -602,7 +602,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi } else if (angular.isDate(viewValue) && !isNaN(viewValue)) { return viewValue; } else if (angular.isString(viewValue)) { - var date = dateParser.parse(viewValue, dateFormat, scope.date) || new Date(viewValue); + var date = dateParser.parse(viewValue, dateFormat, scope.date); if (isNaN(date)) { return undefined; } else { @@ -628,7 +628,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi } else if (angular.isDate(value) && !isNaN(value)) { return true; } else if (angular.isString(value)) { - var date = dateParser.parse(value, dateFormat) || new Date(value); + var date = dateParser.parse(value, dateFormat); return !isNaN(date); } else { return false; @@ -669,7 +669,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi // Detect changes in the view from the text box ngModel.$viewChangeListeners.push(function () { - scope.date = dateParser.parse(ngModel.$viewValue, dateFormat, scope.date) || new Date(ngModel.$viewValue); + scope.date = dateParser.parse(ngModel.$viewValue, dateFormat, scope.date); }); var documentClickBind = function(event) { diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 9ebb52e0bf..4656df8ed2 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1276,21 +1276,21 @@ describe('datepicker directive', function () { }); it('updates the model & calendar when input value changes', function() { - changeInputValueTo(inputEl, 'March 5, 1980'); + changeInputValueTo(inputEl, '2010-09-15'); - expect($rootScope.date.getFullYear()).toEqual(1980); - expect($rootScope.date.getMonth()).toEqual(2); - expect($rootScope.date.getDate()).toEqual(5); + expect($rootScope.date.getFullYear()).toEqual(2010); + expect($rootScope.date.getMonth()).toEqual(8); + expect($rootScope.date.getDate()).toEqual(15); expect(getOptions(true)).toEqual([ - ['24', '25', '26', '27', '28', '29', '01'], - ['02', '03', '04', '05', '06', '07', '08'], - ['09', '10', '11', '12', '13', '14', '15'], - ['16', '17', '18', '19', '20', '21', '22'], - ['23', '24', '25', '26', '27', '28', '29'], - ['30', '31', '01', '02', '03', '04', '05'] + ['29', '30', '31', '01', '02', '03', '04'], + ['05', '06', '07', '08', '09', '10', '11'], + ['12', '13', '14', '15', '16', '17', '18'], + ['19', '20', '21', '22', '23', '24', '25'], + ['26', '27', '28', '29', '30', '01', '02'], + ['03', '04', '05', '06', '07', '08', '09'] ]); - expectSelectedElement( 10 ); + expectSelectedElement( 17 ); }); it('closes when click outside of calendar', function() { @@ -1389,7 +1389,7 @@ describe('datepicker directive', function () { })); it('should change model and update calendar after debounce timeout', function() { - changeInputValueTo(inputEl, 'March 5, 1980'); + changeInputValueTo(inputEl, '1980-03-05'); expect($rootScope.date.getFullYear()).toEqual(2010); expect($rootScope.date.getMonth()).toEqual(9 - 1);