Skip to content

Commit f2405e1

Browse files
justingrantMs2ger
authored andcommitted
Support newer DateTimeFormat output
Update GetFormatterParts implementation in polyfill to avoid failed tests on the latest Intl implementations in newer JS engines (e.g. FF nightly). Port of js-temporal/temporal-polyfill#97
1 parent 7207a1c commit f2405e1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

polyfill/lib/ecmascript.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,14 +2319,11 @@ export const ES = ObjectAssign({}, ES2020, {
23192319
},
23202320
GetFormatterParts: (timeZone, epochMilliseconds) => {
23212321
const formatter = getIntlDateTimeFormatEnUsForTimeZone(timeZone);
2322-
// FIXME: can this use formatToParts instead?
2322+
// Using `format` instead of `formatToParts` for compatibility with older clients
23232323
const datetime = formatter.format(new Date(epochMilliseconds));
2324-
const [date, fullYear, time] = datetime.split(/,\s+/);
2325-
const [month, day] = date.split(' ');
2326-
const [year, era] = fullYear.split(' ');
2327-
const [hour, minute, second] = time.split(':');
2324+
const [month, day, year, era, hour, minute, second] = datetime.split(/[^\w]+/);
23282325
return {
2329-
year: era === 'BC' ? -year + 1 : +year,
2326+
year: era.toUpperCase().startsWith('B') ? -year + 1 : +year,
23302327
month: +month,
23312328
day: +day,
23322329
hour: hour === '24' ? 0 : +hour, // bugs.chromium.org/p/chromium/issues/detail?id=1045791

0 commit comments

Comments
 (0)