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

Commit 65abc82

Browse files
committed
fix(dateLocale): guard for setting midnight to null. Fixes #4780
1 parent bf82512 commit 65abc82

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/components/datepicker/dateUtil.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@
195195
* @param {Date} date
196196
*/
197197
function setDateTimeToMidnight(date) {
198-
date.setHours(0, 0, 0, 0);
198+
if (isValidDate(date)) {
199+
date.setHours(0, 0, 0, 0);
200+
}
199201
}
200202

201203
/**

src/components/datepicker/dateUtil.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ describe('$$mdDateUtil', function() {
304304
expect(dayAtMidnight.getMilliseconds()).toBe(0);
305305
});
306306

307+
it('should not error when trying to set an invalid date to midnight', function() {
308+
dateUtil.setDateTimeToMidnight(new Date(NaN));
309+
dateUtil.setDateTimeToMidnight(null);
310+
dateUtil.setDateTimeToMidnight(undefined);
311+
});
312+
307313
it('should determine whether dates are valid', function() {
308314
expect(dateUtil.isValidDate(null)).toBeFalsy();
309315
expect(dateUtil.isValidDate(undefined)).toBeFalsy();

0 commit comments

Comments
 (0)