diff --git a/packages/widgets/src/clock/component.tsx b/packages/widgets/src/clock/component.tsx index 96a19a14d..bc9cd910e 100644 --- a/packages/widgets/src/clock/component.tsx +++ b/packages/widgets/src/clock/component.tsx @@ -28,6 +28,7 @@ export default function ClockWidget({ options, width, height, displayMode }: Wid const customDateFormat = options.customDateFormat; const timezone = options.useCustomTimezone ? options.timezone : Intl.DateTimeFormat().resolvedOptions().timeZone; const time = useCurrentTime(options); + const zonedTime = time === null ? null : dayjs(time).tz(timezone); const minimumAxis = Math.min(width, height * 1.5); const sizing = minimumAxis < 128 ? "xs" : minimumAxis < 196 ? "sm" : "md"; @@ -50,22 +51,18 @@ export default function ClockWidget({ options, width, height, displayMode }: Wid )} - <time dateTime={dayjs(time).tz(timezone).toISOString()}> - {options.customTimeFormat - ? dayjs(time).tz(timezone).format(customTimeFormat) - : dayjs(time).tz(timezone).format(timeFormat)} + <time dateTime={zonedTime?.toISOString()}> + {zonedTime === null ? "--:--" : zonedTime.format(options.customTimeFormat ? customTimeFormat : timeFormat)} </time> {options.showDate && ( - {options.customDateFormat - ? dayjs(time).tz(timezone).format(customDateFormat) - : dayjs(time).tz(timezone).format(dateFormat)} + {zonedTime?.format(options.customDateFormat ? customDateFormat : dateFormat)} )} {displayMode === "advanced" && ( - {timezone} · UTC{dayjs(time).tz(timezone).format("Z")} + {zonedTime === null ? null : `${timezone} · UTC${zonedTime.format("Z")}`} )} @@ -124,7 +121,7 @@ interface UseCurrentTimeProps { } const useCurrentTime = ({ showSeconds }: UseCurrentTimeProps) => { - const [time, setTime] = useState(() => new Date(0)); + const [time, setTime] = useState(null); const timeoutRef = useRef(null); const intervalRef = useRef(null); const intervalMultiplier = useMemo(() => (showSeconds ? 1 : 60), [showSeconds]);