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

fix(datepicker): remove new Date fallback #4062

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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