Skip to content

Commit

Permalink
fix: readd try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Dec 10, 2023
1 parent f21d4b4 commit d34d9f1
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,50 @@ export function useTimezoneSelect({
const options = useMemo(() => {
return Object.entries(timezones)
.map(zone => {
const now = spacetime.now(zone[0])
const isDstString = now.isDST() ? 'daylight' : 'standard'
const tz = now.timezone()
const tzStrings = soft(zone[0])
try {
const now = spacetime.now(zone[0])
const isDstString = now.isDST() ? 'daylight' : 'standard'
const tz = now.timezone()
const tzStrings = soft(zone[0])

const abbr = tzStrings?.[0]?.[isDstString]?.abbr
const altName = tzStrings?.[0]?.[isDstString]?.name
const abbr = tzStrings?.[0]?.[isDstString]?.abbr
const altName = tzStrings?.[0]?.[isDstString]?.name

const min = tz.current.offset * 60
const hr =
`${(min / 60) ^ 0}:` + (min % 60 === 0 ? '00' : Math.abs(min % 60))
const prefix = `(${displayValue}${hr.includes('-') ? hr : `+${hr}`}) ${
zone[1]
}`
const min = tz.current.offset * 60
const hr =
`${(min / 60) ^ 0}:` + (min % 60 === 0 ? '00' : Math.abs(min % 60))
const prefix = `(${displayValue}${
hr.includes('-') ? hr : `+${hr}`
}) ${zone[1]}`

let label = ''
let label = ''

switch (labelStyle) {
case 'original':
label = prefix
break
case 'altName':
label = `${prefix} ${altName ? `(${altName})` : ''}`
break
case 'abbrev':
label = `${prefix} (${abbr})`
break
case 'offsetHidden':
label = `${prefix.replace(/^\(.*?\)\s*/, '')}`
break
default:
label = `${prefix}`
}
switch (labelStyle) {
case 'original':
label = prefix
break
case 'altName':
label = `${prefix} ${altName ? `(${altName})` : ''}`
break
case 'abbrev':
label = `${prefix} (${abbr})`
break
case 'offsetHidden':
label = `${prefix.replace(/^\(.*?\)\s*/, '')}`
break
default:
label = `${prefix}`
}

return {
value: tz.name,
label: label,
offset: tz.current.offset,
abbrev: abbr,
altName: altName,
return {
value: tz.name,
label: label,
offset: tz.current.offset,
abbrev: abbr,
altName: altName,
}
} catch (e) {
return null
}
})
.filter(Boolean)
Expand Down

0 comments on commit d34d9f1

Please sign in to comment.