Skip to content

Commit 1362610

Browse files
committed
Simplify date component validity check
1 parent 8597cac commit 1362610

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/material/core/datetime/native-date-adapter.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
176176
return new Date(value);
177177
}
178178

179-
const dateParts = (value as string)
179+
const dateParts = value
180180
.trim()
181181
.split(DATE_COMPONENT_SEPARATOR_REGEX)
182182
.map(part => parseInt(part, 10))
@@ -221,13 +221,14 @@ export class NativeDateAdapter extends DateAdapter<Date> {
221221
}
222222
}
223223

224-
if (
225-
year !== null &&
226-
month !== null &&
227-
day !== null &&
228-
this._dateComponentsAreValid(year, month, day)
229-
) {
230-
return this.createDate(year, month, day);
224+
if (year !== null && month !== null && day !== null) {
225+
const date = this.createDate(year, month, day);
226+
227+
if (date.getFullYear() === year && date.getMonth() === month && date.getDate() === day) {
228+
return date;
229+
}
230+
231+
return this.invalid();
231232
}
232233

233234
return this._nativeParseFallback(value);

0 commit comments

Comments
 (0)