Skip to content

Commit 2f6e6b4

Browse files
authored
Remove erroneous options from Safari's Intl.DateTimeFormat resolvedOptions. (#144)
1 parent 5df9d9f commit 2f6e6b4

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

lib/intl.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,31 @@ function adjustFormatterTimeZone(
208208
if (!timeZone) return formatter;
209209
const options = formatter.resolvedOptions();
210210
if (options.timeZone === timeZone) return formatter;
211-
// Existing Intl isn't typed to accept Temporal-specific options, but will not
212-
// break at runtime if we pass them. Also, the lib types for resolved options
213-
// are less restrictive than the types for options. For example, `weekday` is
211+
// Existing Intl isn't typed to accept Temporal-specific options and the lib
212+
// types for resolved options are less restrictive than the types for options.
213+
// For example, `weekday` is
214214
// `'long' | 'short' | 'narrow'` in options but `string` in resolved options.
215215
// TODO: investigate why, and file an issue against TS if it's a bug.
216+
if ((options as any)['dateStyle'] || (options as any)['timeStyle']) {
217+
// Unfortunately, Safari's resolvedOptions include parameters that will
218+
// cause errors at runtime if passed along with
219+
// dateStyle or timeStyle options as per
220+
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components.
221+
// This has been fixed in newer versions of Safari:
222+
// https://bugs.webkit.org/show_bug.cgi?id=231041
223+
delete options['weekday'];
224+
delete options['era'];
225+
delete options['year'];
226+
delete options['month'];
227+
delete options['day'];
228+
delete options['hour'];
229+
delete options['minute'];
230+
delete options['second'];
231+
delete options['timeZoneName'];
232+
delete (options as any)['hourCycle'];
233+
delete options['hour12'];
234+
delete (options as any)['dayPeriod'];
235+
}
216236
return new IntlDateTimeFormat(options.locale, { ...(options as globalThis.Intl.DateTimeFormatOptions), timeZone });
217237
}
218238

0 commit comments

Comments
 (0)