Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(datepicker): *BREAKING CHANGE* remove new Date fallback
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
wesleycho committed Aug 1, 2015
1 parent 2004757 commit ab4580f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 12 additions & 12 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ab4580f

Please sign in to comment.