fix(datetime): hourCycle formats hour correctly (#25869)

resolves #25862
This commit is contained in:
Liam DeBeasi
2022-09-06 09:24:50 -05:00
committed by GitHub
parent 2d3661ae38
commit 1a1491df02
2 changed files with 18 additions and 1 deletions

View File

@ -155,4 +155,17 @@ describe('getLocalizedTime', () => {
expect(getLocalizedTime('en-US', datetimeParts, false)).toEqual('9:40 AM');
});
it('should avoid Chromium bug when using 12 hour time in a 24 hour locale', () => {
const datetimeParts = {
day: 1,
month: 1,
year: 2022,
hour: 0,
minute: 0,
tzOffset: 0,
};
expect(getLocalizedTime('en-GB', datetimeParts, false)).toEqual('12:00 am');
});
});

View File

@ -19,7 +19,11 @@ export const getLocalizedTime = (locale: string, refParts: DatetimeParts, use24H
hour: 'numeric',
minute: 'numeric',
timeZone: 'UTC',
hour12: !use24Hour,
/**
* We use hourCycle here instead of hour12 due to:
* https://bugs.chromium.org/p/chromium/issues/detail?id=1347316&q=hour12&can=2
*/
hourCycle: use24Hour ? 'h23' : 'h12',
}).format(
new Date(
convertDataToISO({