Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Update and map deprecated timezone
Browse files Browse the repository at this point in the history
Co-authored-by: Trish Rempel <[email protected]>
Co-authored-by: Christina Tran <[email protected]>
Co-authored-by: Jess Telford <[email protected]>
  • Loading branch information
4 people committed Jan 8, 2025
1 parent 73c7dd1 commit 8588780
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-countries-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/react-i18n': patch
---

Map deprecated timezone
5 changes: 5 additions & 0 deletions .changeset/shaggy-dots-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/dates': patch
---

Update deprecated timezone for Europe/Kyiv
1 change: 1 addition & 0 deletions packages/dates/src/deprecated-timezones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 16 additions & 4 deletions packages/react-i18n/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TimeUnit,
isLessThanOneWeekAway,
isLessThanOneYearAway,
mapDeprecatedTimezones,
} from '@shopify/dates';
import {
formatName as importedFormatName,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -330,25 +331,32 @@ 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:
return this.formatDate(date, {...formatOptions, ...dateStyle[style]});
}
}

return formatDate(date, locale, {...formatOptions, timeZone});
return formatDate(date, locale, {
...formatOptions,
timeZone: normalizedTimezone,
});
}

ordinal(amount: number) {
Expand Down Expand Up @@ -825,4 +833,8 @@ export class I18n {
private defaultOnError(error: I18nError) {
throw error;
}

private normalizeTimezone(timeZone?: string) {
return timeZone ? mapDeprecatedTimezones(timeZone) : undefined;
}
}

0 comments on commit 8588780

Please sign in to comment.