mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
web/rightpanel: ignore timezone if value is unsupported
This commit is contained in:
parent
9cff332671
commit
fabf3404af
1 changed files with 12 additions and 4 deletions
|
@ -27,14 +27,19 @@ const currentTimeAdjusted = (tz: string) => {
|
||||||
timeZoneName: "short",
|
timeZoneName: "short",
|
||||||
timeZone: tz,
|
timeZone: tz,
|
||||||
}).format(new Date())
|
}).format(new Date())
|
||||||
} catch (e) {
|
} catch {
|
||||||
return `${e}`
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ClockElement = ({ tz }: { tz: string }) => {
|
const ClockElement = ({ tz }: { tz: string }) => {
|
||||||
const [time, setTime] = useState(currentTimeAdjusted(tz))
|
const cta = currentTimeAdjusted(tz)
|
||||||
|
const isValidTZ = cta !== null
|
||||||
|
const [time, setTime] = useState(cta)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!isValidTZ) {
|
||||||
|
return
|
||||||
|
}
|
||||||
let interval: number | undefined
|
let interval: number | undefined
|
||||||
const updateTime = () => setTime(currentTimeAdjusted(tz))
|
const updateTime = () => setTime(currentTimeAdjusted(tz))
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
|
@ -42,8 +47,11 @@ const ClockElement = ({ tz }: { tz: string }) => {
|
||||||
updateTime()
|
updateTime()
|
||||||
}, (1001 - Date.now() % 1000))
|
}, (1001 - Date.now() % 1000))
|
||||||
return () => interval ? clearInterval(interval) : clearTimeout(timeout)
|
return () => interval ? clearInterval(interval) : clearTimeout(timeout)
|
||||||
}, [tz])
|
}, [tz, isValidTZ])
|
||||||
|
|
||||||
|
if (!isValidTZ) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
return <>
|
return <>
|
||||||
<div title={tz}>Time:</div>
|
<div title={tz}>Time:</div>
|
||||||
<div title={tz}>{time}</div>
|
<div title={tz}>{time}</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue