@@ -283,7 +283,12 @@ export class NativeDateAdapter extends DateAdapter<Date> {
283
283
284
284
/** Creates a date but allows the month and date to overflow. */
285
285
private _createDateWithOverflow ( year : number , month : number , date : number ) {
286
- return this . _correctYear ( new Date ( year , month , date ) , year ) ;
286
+ // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
287
+ // To work around this we use `setFullYear` and `setHours` instead.
288
+ const d = new Date ( ) ;
289
+ d . setFullYear ( year , month , date ) ;
290
+ d . setHours ( 0 , 0 , 0 , 0 ) ;
291
+ return d ;
287
292
}
288
293
289
294
/**
@@ -318,22 +323,11 @@ export class NativeDateAdapter extends DateAdapter<Date> {
318
323
* @returns A Date object with its UTC representation based on the passed in date info
319
324
*/
320
325
private _format ( dtf : Intl . DateTimeFormat , date : Date ) {
321
- const year = date . getFullYear ( ) ;
322
- const d = new Date ( Date . UTC (
323
- year , date . getMonth ( ) , date . getDate ( ) , date . getHours ( ) ,
324
- date . getMinutes ( ) , date . getSeconds ( ) , date . getMilliseconds ( ) ) ) ;
325
- return dtf . format ( this . _correctYear ( d , year ) ) ;
326
- }
327
-
328
- /**
329
- * Corrects the year of a date, accounting for the fact that JS
330
- * native Date treats years between 0 and 99 as abbreviations for 19xx.
331
- */
332
- private _correctYear ( date : Date , intendedYear : number ) : Date {
333
- if ( intendedYear >= 0 && intendedYear < 100 ) {
334
- date . setFullYear ( this . getYear ( date ) - 1900 ) ;
335
- }
336
-
337
- return date ;
326
+ // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
327
+ // To work around this we use `setUTCFullYear` and `setUTCHours` instead.
328
+ const d = new Date ( ) ;
329
+ d . setUTCFullYear ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) ) ;
330
+ d . setUTCHours ( date . getHours ( ) , date . getMinutes ( ) , date . getSeconds ( ) , date . getMilliseconds ( ) ) ;
331
+ return dtf . format ( d ) ;
338
332
}
339
333
}
0 commit comments