Merge branch feat/v2-stack-final-runtime-dnd into feat/v2-stack-final-runtime-modernization
# Conflicts: # packages/widgets/src/clock/component.tsx
This commit is contained in:
1 file changed
+6
-9
@@ -28,6 +28,7 @@ export default function ClockWidget({ options, width, height, displayMode }: Wid
|
|||||||
const customDateFormat = options.customDateFormat;
|
const customDateFormat = options.customDateFormat;
|
||||||
const timezone = options.useCustomTimezone ? options.timezone : Intl.DateTimeFormat().resolvedOptions().timeZone;
|
const timezone = options.useCustomTimezone ? options.timezone : Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
const time = useCurrentTime(options);
|
const time = useCurrentTime(options);
|
||||||
|
const zonedTime = time === null ? null : dayjs(time).tz(timezone);
|
||||||
|
|
||||||
const minimumAxis = Math.min(width, height * 1.5);
|
const minimumAxis = Math.min(width, height * 1.5);
|
||||||
const sizing = minimumAxis < 128 ? "xs" : minimumAxis < 196 ? "sm" : "md";
|
const sizing = minimumAxis < 128 ? "xs" : minimumAxis < 196 ? "sm" : "md";
|
||||||
@@ -50,22 +51,18 @@ export default function ClockWidget({ options, width, height, displayMode }: Wid
|
|||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Title className="clock-time-text" fw={700} order={sizing === "md" ? 2 : sizing === "sm" ? 4 : 6} lh="1">
|
<Title className="clock-time-text" fw={700} order={sizing === "md" ? 2 : sizing === "sm" ? 4 : 6} lh="1">
|
||||||
<time dateTime={dayjs(time).tz(timezone).toISOString()}>
|
<time dateTime={zonedTime?.toISOString()}>
|
||||||
{options.customTimeFormat
|
{zonedTime === null ? "--:--" : zonedTime.format(options.customTimeFormat ? customTimeFormat : timeFormat)}
|
||||||
? dayjs(time).tz(timezone).format(customTimeFormat)
|
|
||||||
: dayjs(time).tz(timezone).format(timeFormat)}
|
|
||||||
</time>
|
</time>
|
||||||
</Title>
|
</Title>
|
||||||
{options.showDate && (
|
{options.showDate && (
|
||||||
<Text className="clock-date-text" size={sizing} lineClamp={1}>
|
<Text className="clock-date-text" size={sizing} lineClamp={1}>
|
||||||
{options.customDateFormat
|
{zonedTime?.format(options.customDateFormat ? customDateFormat : dateFormat)}
|
||||||
? dayjs(time).tz(timezone).format(customDateFormat)
|
|
||||||
: dayjs(time).tz(timezone).format(dateFormat)}
|
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
{displayMode === "advanced" && (
|
{displayMode === "advanced" && (
|
||||||
<Text size="xs" c="dimmed" lineClamp={1}>
|
<Text size="xs" c="dimmed" lineClamp={1}>
|
||||||
{timezone} · UTC{dayjs(time).tz(timezone).format("Z")}
|
{zonedTime === null ? null : `${timezone} · UTC${zonedTime.format("Z")}`}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -124,7 +121,7 @@ interface UseCurrentTimeProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const useCurrentTime = ({ showSeconds }: UseCurrentTimeProps) => {
|
const useCurrentTime = ({ showSeconds }: UseCurrentTimeProps) => {
|
||||||
const [time, setTime] = useState(() => new Date(0));
|
const [time, setTime] = useState<Date | null>(null);
|
||||||
const timeoutRef = useRef<NodeJS.Timeout>(null);
|
const timeoutRef = useRef<NodeJS.Timeout>(null);
|
||||||
const intervalRef = useRef<NodeJS.Timeout>(null);
|
const intervalRef = useRef<NodeJS.Timeout>(null);
|
||||||
const intervalMultiplier = useMemo(() => (showSeconds ? 1 : 60), [showSeconds]);
|
const intervalMultiplier = useMemo(() => (showSeconds ? 1 : 60), [showSeconds]);
|
||||||
|
|||||||
Reference in new issue
Block a user