Skip to content

Commit ef55cda

Browse files
committed
fix(utils): fall back to Intl-resolved abbreviation for unmapped timezones
getTimezoneAbbreviation only covered 9 hardcoded IANA zones and returned the raw IANA string for everything else, degrading schedule descriptions for zones like Europe/Berlin or America/Toronto (caught by Greptile). The deleted local implementation in schedules/utils.ts resolved any valid IANA timezone generically via Intl.DateTimeFormat's short timeZoneName. Restore that as a fallback so only genuinely invalid timezone strings return themselves unchanged.
1 parent 1b4c9b8 commit ef55cda

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/utils/src/formatting.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ describe('getTimezoneAbbreviation', () => {
2828
expect(getTimezoneAbbreviation('Unknown/Zone')).toBe('Unknown/Zone')
2929
})
3030

31+
it('resolves a valid IANA timezone outside the hardcoded map via Intl instead of the raw string', () => {
32+
const result = getTimezoneAbbreviation('Europe/Berlin', new Date('2023-01-15'))
33+
expect(result).not.toBe('Europe/Berlin')
34+
})
35+
3136
it('returns PST or PDT for Los Angeles', () => {
3237
const result = getTimezoneAbbreviation('America/Los_Angeles', new Date('2023-01-15'))
3338
expect(['PST', 'PDT']).toContain(result)

packages/utils/src/formatting.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ export function getTimezoneAbbreviation(timezone: string, date: Date = new Date(
4848
return timezoneMap[timezone].standard
4949
}
5050

51-
return timezone
51+
try {
52+
const parts = new Intl.DateTimeFormat('en-US', {
53+
timeZone: timezone,
54+
timeZoneName: 'short',
55+
}).formatToParts(date)
56+
return parts.find((p) => p.type === 'timeZoneName')?.value || timezone
57+
} catch {
58+
return timezone
59+
}
5260
}
5361

5462
/**

0 commit comments

Comments
 (0)