fix(common): format day-periods that cross midnight (#36611)
When formatting a time with the `b` or `B` format codes, the rendered string was not correctly handling day periods that spanned midnight. Instead the logic was falling back to the default case of `AM`. Now the logic has been updated so that it matches times that are within a day period that spans midnight, so it will now render the correct output, such as `at night` in the case of English. Applications that are using either `formatDate()` or `DatePipe` and any of the `b` or `B` format codes will be affected by this change. Fixes #36566 PR Close #36611
This commit is contained in:

committed by
atscott

parent
074266b896
commit
c6e5fc4fbe
@ -202,6 +202,19 @@ describe('Format date', () => {
|
||||
BBBBB: 'mi',
|
||||
};
|
||||
|
||||
const midnightCrossingPeriods: any = {
|
||||
b: 'night',
|
||||
bb: 'night',
|
||||
bbb: 'night',
|
||||
bbbb: 'night',
|
||||
bbbbb: 'night',
|
||||
B: 'at night',
|
||||
BB: 'at night',
|
||||
BBB: 'at night',
|
||||
BBBB: 'at night',
|
||||
BBBBB: 'at night',
|
||||
};
|
||||
|
||||
Object.keys(dateFixtures).forEach((pattern: string) => {
|
||||
expectDateFormatAs(date, pattern, dateFixtures[pattern]);
|
||||
});
|
||||
@ -209,6 +222,11 @@ describe('Format date', () => {
|
||||
Object.keys(isoStringWithoutTimeFixtures).forEach((pattern: string) => {
|
||||
expectDateFormatAs(isoStringWithoutTime, pattern, isoStringWithoutTimeFixtures[pattern]);
|
||||
});
|
||||
|
||||
const nightTime = new Date(2015, 5, 15, 2, 3, 1, 550);
|
||||
Object.keys(midnightCrossingPeriods).forEach(pattern => {
|
||||
expectDateFormatAs(nightTime, pattern, midnightCrossingPeriods[pattern]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should format with timezones', () => {
|
||||
|
Reference in New Issue
Block a user