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

Commit d2c9fae

Browse files
ginabaktrishrempelchristina-tranjesstelford
authored
Update and Map Deprecated Timezone (#2842)
Correctly support deprecated timezones in older browsers when calling `formatDate()` For example, modern browsers support both `Europe/Kyiv` and (the now deprecated) `Europe/Kiev`, but browsers as recent as Chrome 131 on MacOS only support `Europe/Kiev`. Note: This is a purely internal change which should not effect the result of calling `formatDate()`. Co-authored-by: Trish Rempel <[email protected]> Co-authored-by: Christina Tran <[email protected]> Co-authored-by: Jess Telford <[email protected]>
1 parent 73c7dd1 commit d2c9fae

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

.changeset/light-students-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/dates': patch
3+
---
4+
5+
Correctly support deprecated timezones in older browsers when calling `formatDate()`. For example, modern browsers support both `Europe/Kyiv` and (the now deprecated) `Europe/Kiev`, but browsers as recent as Chrome 131 on MacOS only support `Europe/Kiev`. Note: This is a purely internal change which should not effect the result of calling `formatDate()`.

packages/dates/src/deprecated-timezones.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const deprecatedTimezones: {[key: string]: string} = {
2828
'Canada/Yukon': 'America/Whitehorse',
2929
'Chile/Continental': 'America/Santiago',
3030
'Chile/EasterIsland': 'Pacific/Easter',
31+
'Europe/Kyiv': 'Europe/Kiev',
3132
Cuba: 'America/Havana',
3233
Egypt: 'Africa/Cairo',
3334
Eire: 'Europe/Dublin',

packages/dates/src/utilities/formatDate.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {mapDeprecatedTimezones} from '../map-deprecated-timezones';
2+
13
const intl = new Map<string, Intl.DateTimeFormat>();
24
export function memoizedGetDateTimeFormat(
35
locales?: string | string[],
@@ -58,7 +60,12 @@ export function formatDate(
5860
}).format(adjustedDate);
5961
}
6062

61-
return memoizedGetDateTimeFormat(locales, options).format(date);
63+
return memoizedGetDateTimeFormat(locales, {
64+
...options,
65+
timeZone: options.timeZone
66+
? mapDeprecatedTimezones(options.timeZone)
67+
: undefined,
68+
}).format(date);
6269
}
6370

6471
export function dateTimeFormatCacheKey(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {formatDate} from '../formatDate';
2+
3+
jest.mock('../../map-deprecated-timezones', () => ({
4+
mapDeprecatedTimezones: jest.fn(),
5+
}));
6+
7+
const mapDeprecatedTimezones: jest.Mock = jest.requireMock(
8+
'../../map-deprecated-timezones',
9+
).mapDeprecatedTimezones;
10+
11+
describe('formatDate', () => {
12+
it('maps the deprecated timezone', () => {
13+
const date = new Date();
14+
const locale = 'en-UA';
15+
const options: Intl.DateTimeFormatOptions = {
16+
timeZone: 'Europe/Kyiv',
17+
};
18+
19+
formatDate(date, locale, options);
20+
expect(mapDeprecatedTimezones).toHaveBeenCalledWith('Europe/Kyiv');
21+
});
22+
});

0 commit comments

Comments
 (0)