Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(dateLocale): guard for setting midnight to null. Fixes #4780
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Sep 22, 2015
1 parent bf82512 commit 65abc82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/datepicker/dateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@
* @param {Date} date
*/
function setDateTimeToMidnight(date) {
date.setHours(0, 0, 0, 0);
if (isValidDate(date)) {
date.setHours(0, 0, 0, 0);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/components/datepicker/dateUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ describe('$$mdDateUtil', function() {
expect(dayAtMidnight.getMilliseconds()).toBe(0);
});

it('should not error when trying to set an invalid date to midnight', function() {
dateUtil.setDateTimeToMidnight(new Date(NaN));
dateUtil.setDateTimeToMidnight(null);
dateUtil.setDateTimeToMidnight(undefined);
});

it('should determine whether dates are valid', function() {
expect(dateUtil.isValidDate(null)).toBeFalsy();
expect(dateUtil.isValidDate(undefined)).toBeFalsy();
Expand Down

0 comments on commit 65abc82

Please sign in to comment.