Skip to content

Commit

Permalink
fix(@formatjs/ecma402-abstract): fix IsValidTimeZoneName to include t…
Browse files Browse the repository at this point in the history
…arget zone from backward, fix #2951
  • Loading branch information
longlho committed Jun 5, 2021
1 parent 1d7896c commit c18ee8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/ecma402-abstract/IsValidTimeZoneName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ export function IsValidTimeZoneName(
uppercaseLinks,
}: {
tzData: Record<string, unknown>
uppercaseLinks: Record<string, unknown>
uppercaseLinks: Record<string, string>
}
): boolean {
const uppercasedTz = tz.toUpperCase()
const zoneNames = new Set()
const linkNames = new Set()
Object.keys(tzData)
.map(z => z.toUpperCase())
.forEach(z => zoneNames.add(z))
return zoneNames.has(uppercasedTz) || uppercasedTz in uppercaseLinks
Object.keys(uppercaseLinks).forEach(linkName => {
linkNames.add(linkName.toUpperCase())
zoneNames.add(uppercaseLinks[linkName].toUpperCase())
})
return zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz)
}
9 changes: 9 additions & 0 deletions packages/intl-datetimeformat/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ describe('Intl.DateTimeFormat', function () {
})
expect(() => dtf.formatRange(date1, date2)).not.toThrow()
})
it('GH issue #2951', function () {
const date1 = new Date(Date.UTC(2021, 4, 19, 9, 0)) // "May 19, 2021, 9 AM"
const dtf = new DateTimeFormat('en', {
hour: 'numeric',
minute: 'numeric',
timeZone: 'Etc/UTC',
})
expect(() => dtf.format(date1)).not.toThrow()
})
it.skip('GH issue #2915', function () {
const date1 = new Date(Date.UTC(2021, 4, 19, 9, 0)) // "May 19, 2021, 9 AM"
const date2 = new Date(Date.UTC(2021, 5, 19, 17, 0)) // "Jun 19, 2021, 5 PM"
Expand Down

0 comments on commit c18ee8b

Please sign in to comment.