Skip to content

Commit 47f9132

Browse files
authored
Fix GetFormatterParts for Firefox Nightly (#97)
* GetFormatterParts: Accept 1+ non-alphanumeric characters as separators * GetFormatterParts: case-insensitively look at the first character of the era only
1 parent 64b2eab commit 47f9132

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/ecmascript.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,14 +2832,11 @@ export function GetIANATimeZonePreviousTransition(epochNanoseconds: bigInt.BigIn
28322832
// ts-prune-ignore-next TODO: remove this after tests are converted to TS
28332833
export function GetFormatterParts(timeZone: string, epochMilliseconds: number) {
28342834
const formatter = getIntlDateTimeFormatEnUsForTimeZone(timeZone);
2835-
// FIXME: can this use formatToParts instead?
2835+
// Using `format` instead of `formatToParts` for compatibility with older clients
28362836
const datetime = formatter.format(new Date(epochMilliseconds));
2837-
const [date, fullYear, time] = datetime.split(/,\s+/);
2838-
const [month, day] = date.split(' ');
2839-
const [year, era] = fullYear.split(' ');
2840-
const [hour, minute, second] = time.split(':');
2837+
const [month, day, year, era, hour, minute, second] = datetime.split(/[^\w]+/);
28412838
return {
2842-
year: era === 'BC' ? -year + 1 : +year,
2839+
year: era.toUpperCase().startsWith('B') ? -year + 1 : +year,
28432840
month: +month,
28442841
day: +day,
28452842
hour: hour === '24' ? 0 : +hour, // bugs.chromium.org/p/chromium/issues/detail?id=1045791

0 commit comments

Comments
 (0)