@@ -347,6 +347,32 @@ describe('Format date', () => {
347347 . toEqual ( '10:14 AM' ) ;
348348 } ) ;
349349
350+ // The following test is disabled because backwards compatibility requires that date-only ISO
351+ // strings are parsed with the local timezone.
352+
353+ // it('should create UTC date objects when an ISO string is passed with no time components',
354+ // () => {
355+ // expect(formatDate('2019-09-20', `MMM d, y, h:mm:ss a ZZZZZ`, ɵDEFAULT_LOCALE_ID))
356+ // .toEqual('Sep 20, 2019, 12:00:00 AM Z');
357+ // });
358+
359+ // This test is to ensure backward compatibility for parsing date-only ISO strings.
360+ it ( 'should create local timezone date objects when an ISO string is passed with no time components' ,
361+ ( ) => {
362+ // Dates created with individual components are evaluated against the local timezone. See
363+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#Individual_date_and_time_component_values
364+ const localDate = new Date ( 2019 , 8 , 20 , 0 , 0 , 0 , 0 ) ;
365+ expect ( formatDate ( '2019-09-20' , `MMM d, y, h:mm:ss a ZZZZZ` , ɵDEFAULT_LOCALE_ID ) )
366+ . toEqual ( formatDate ( localDate , `MMM d, y, h:mm:ss a ZZZZZ` , ɵDEFAULT_LOCALE_ID ) ) ;
367+ } ) ;
368+
369+ it ( 'should create local timezone date objects when an ISO string is passed with time components' ,
370+ ( ) => {
371+ const localDate = new Date ( 2019 , 8 , 20 , 0 , 0 , 0 , 0 ) ;
372+ expect ( formatDate ( '2019-09-20T00:00:00' , `MMM d, y, h:mm:ss a ZZZZZ` , ɵDEFAULT_LOCALE_ID ) )
373+ . toEqual ( formatDate ( localDate , `MMM d, y, h:mm:ss a ZZZZZ` , ɵDEFAULT_LOCALE_ID ) ) ;
374+ } ) ;
375+
350376 it ( 'should remove bidi control characters' ,
351377 ( ) => expect ( formatDate ( date , 'MM/dd/yyyy' , ɵDEFAULT_LOCALE_ID ) ! . length ) . toEqual ( 10 ) ) ;
352378
@@ -389,6 +415,17 @@ describe('Format date', () => {
389415 expect ( formatDate ( '2013-12-29' , 'YYYY' , 'en' ) ) . toEqual ( '2014' ) ;
390416 expect ( formatDate ( '2010-01-02' , 'YYYY' , 'en' ) ) . toEqual ( '2009' ) ;
391417 expect ( formatDate ( '2010-01-04' , 'YYYY' , 'en' ) ) . toEqual ( '2010' ) ;
418+ expect ( formatDate ( '0049-01-01' , 'YYYY' , 'en' ) ) . toEqual ( '0048' ) ;
419+ expect ( formatDate ( '0049-01-04' , 'YYYY' , 'en' ) ) . toEqual ( '0049' ) ;
392420 } ) ;
421+
422+ // https://github.com/angular/angular/issues/40377
423+ it ( 'should format date with year between 0 and 99 correctly' , ( ) => {
424+ expect ( formatDate ( '0098-01-11' , 'YYYY' , ɵDEFAULT_LOCALE_ID ) ) . toEqual ( '0098' ) ;
425+ expect ( formatDate ( '0099-01-11' , 'YYYY' , ɵDEFAULT_LOCALE_ID ) ) . toEqual ( '0099' ) ;
426+ expect ( formatDate ( '0100-01-11' , 'YYYY' , ɵDEFAULT_LOCALE_ID ) ) . toEqual ( '0100' ) ;
427+ expect ( formatDate ( '0001-01-11' , 'YYYY' , ɵDEFAULT_LOCALE_ID ) ) . toEqual ( '0001' ) ;
428+ expect ( formatDate ( '0000-01-11' , 'YYYY' , ɵDEFAULT_LOCALE_ID ) ) . toEqual ( '0000' ) ;
429+ } ) ;
393430 } ) ;
394431} ) ;
0 commit comments