@@ -146,7 +146,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
146
146
return new Date ( value ) ;
147
147
}
148
148
149
- const dateParts = ( value as string )
149
+ const dateParts = value
150
150
. trim ( )
151
151
. split ( DATE_COMPONENT_SEPARATOR_REGEX )
152
152
. map ( part => parseInt ( part , 10 ) )
@@ -191,13 +191,14 @@ export class NativeDateAdapter extends DateAdapter<Date> {
191
191
}
192
192
}
193
193
194
- if (
195
- year !== null &&
196
- month !== null &&
197
- day !== null &&
198
- this . _dateComponentsAreValid ( year , month , day )
199
- ) {
200
- return this . createDate ( year , month , day ) ;
194
+ if ( year !== null && month !== null && day !== null ) {
195
+ const date = this . createDate ( year , month , day ) ;
196
+
197
+ if ( date . getFullYear ( ) === year && date . getMonth ( ) === month && date . getDate ( ) === day ) {
198
+ return date ;
199
+ }
200
+
201
+ return this . invalid ( ) ;
201
202
}
202
203
203
204
return this . _nativeParseFallback ( value ) ;
@@ -348,21 +349,4 @@ export class NativeDateAdapter extends DateAdapter<Date> {
348
349
date . getUTCMilliseconds ( ) ,
349
350
) ;
350
351
}
351
-
352
- private _dateComponentsAreValid ( year : number , month : number , day : number ) {
353
- if ( year < 0 || year > 9999 || month < 0 || month > 11 || day < 1 || day > 31 ) {
354
- return false ;
355
- }
356
-
357
- if ( month === 1 ) {
358
- const isLeapYear = ( year % 4 === 0 && year % 100 !== 0 ) || year % 400 === 0 ;
359
- return isLeapYear ? day <= 29 : day <= 28 ;
360
- }
361
-
362
- if ( month === 3 || month === 5 || month === 8 || month === 10 ) {
363
- return day <= 30 ;
364
- }
365
-
366
- return true ;
367
- }
368
352
}
0 commit comments