From 858878066ab106d42d7385019f43a1c42c9172c9 Mon Sep 17 00:00:00 2001 From: Gina Bak Date: Tue, 7 Jan 2025 17:19:03 -0800 Subject: [PATCH] Update and map deprecated timezone Co-authored-by: Trish Rempel Co-authored-by: Christina Tran Co-authored-by: Jess Telford --- .changeset/rude-countries-tickle.md | 5 +++++ .changeset/shaggy-dots-eat.md | 5 +++++ packages/dates/src/deprecated-timezones.ts | 1 + packages/react-i18n/src/i18n.ts | 20 ++++++++++++++++---- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 .changeset/rude-countries-tickle.md create mode 100644 .changeset/shaggy-dots-eat.md diff --git a/.changeset/rude-countries-tickle.md b/.changeset/rude-countries-tickle.md new file mode 100644 index 0000000000..36b001635d --- /dev/null +++ b/.changeset/rude-countries-tickle.md @@ -0,0 +1,5 @@ +--- +'@shopify/react-i18n': patch +--- + +Map deprecated timezone diff --git a/.changeset/shaggy-dots-eat.md b/.changeset/shaggy-dots-eat.md new file mode 100644 index 0000000000..d3c3ce390f --- /dev/null +++ b/.changeset/shaggy-dots-eat.md @@ -0,0 +1,5 @@ +--- +'@shopify/dates': patch +--- + +Update deprecated timezone for Europe/Kyiv diff --git a/packages/dates/src/deprecated-timezones.ts b/packages/dates/src/deprecated-timezones.ts index 227b0513c8..30f665f8ac 100644 --- a/packages/dates/src/deprecated-timezones.ts +++ b/packages/dates/src/deprecated-timezones.ts @@ -28,6 +28,7 @@ export const deprecatedTimezones: {[key: string]: string} = { 'Canada/Yukon': 'America/Whitehorse', 'Chile/Continental': 'America/Santiago', 'Chile/EasterIsland': 'Pacific/Easter', + 'Europe/Kyiv': 'Europe/Kiev', Cuba: 'America/Havana', Egypt: 'Africa/Cairo', Eire: 'Europe/Dublin', diff --git a/packages/react-i18n/src/i18n.ts b/packages/react-i18n/src/i18n.ts index 49c9dfab3f..9fb4e9c16f 100644 --- a/packages/react-i18n/src/i18n.ts +++ b/packages/react-i18n/src/i18n.ts @@ -11,6 +11,7 @@ import { TimeUnit, isLessThanOneWeekAway, isLessThanOneYearAway, + mapDeprecatedTimezones, } from '@shopify/dates'; import { formatName as importedFormatName, @@ -132,7 +133,7 @@ export class I18n { this.locale = locale; this.defaultCountry = country; this.defaultCurrency = currency; - this.defaultTimezone = timezone; + this.defaultTimezone = this.normalizeTimezone(timezone); this.pseudolocalize = pseudolocalize; this.defaultInterpolate = interpolate; this.onError = onError || this.defaultOnError; @@ -330,17 +331,21 @@ export class I18n { ): string { const {locale, defaultTimezone} = this; const {timeZone = defaultTimezone} = options; + const normalizedTimezone = this.normalizeTimezone(timeZone); const {style = undefined, ...formatOptions} = options || {}; if (style) { switch (style) { case DateStyle.Humanize: - return this.humanizeDate(date, {...formatOptions, timeZone}); + return this.humanizeDate(date, { + ...formatOptions, + timeZone: normalizedTimezone, + }); case DateStyle.DateTime: return this.formatDateTime(date, { ...formatOptions, - timeZone, + timeZone: normalizedTimezone, ...dateStyle[style], }); default: @@ -348,7 +353,10 @@ export class I18n { } } - return formatDate(date, locale, {...formatOptions, timeZone}); + return formatDate(date, locale, { + ...formatOptions, + timeZone: normalizedTimezone, + }); } ordinal(amount: number) { @@ -825,4 +833,8 @@ export class I18n { private defaultOnError(error: I18nError) { throw error; } + + private normalizeTimezone(timeZone?: string) { + return timeZone ? mapDeprecatedTimezones(timeZone) : undefined; + } }