refactor: drop clock option compatibility

This commit is contained in:
ajnart committed 2026-08-20 16:01:27 +02:00
1 parent 18bfb26b91
commit a138e8d8b7
7 files changed
+32 -63

No files matched your search

+2 -4
View File
@@ -222,13 +222,11 @@ const ClockTime = ({
if (!entry.zonedTime) return null;
let formattedTime = formatLocalizedTime(now, locale, {
hour12: clockTimeFormatUses12Hours(options.customTimeFormat, options.is24HourFormat),
includeSeconds: clockTimeFormatShowsSeconds(options.customTimeFormat, options.showSeconds),
includeSeconds: clockTimeFormatShowsSeconds(options.customTimeFormat),
timeZone: entry.timeZone,
});
if (primary) {
formattedTime = entry.zonedTime.format(
resolveClockTimeFormat(options.customTimeFormat, options.is24HourFormat, options.showSeconds),
);
formattedTime = entry.zonedTime.format(resolveClockTimeFormat(options.customTimeFormat, options.is24HourFormat));
}
const accessibleDate = formatLocalizedDate(now, locale, {
dateStyle: "medium",
+3 -8
View File
@@ -15,7 +15,7 @@ dayjs.extend(advancedFormat);
export default function ClockWidget({ options, width, height, displayMode }: WidgetComponentProps<"clock">) {
const isAdvanced = displayMode === "advanced";
const showSeconds = clockTimeFormatShowsSeconds(options.customTimeFormat, options.showSeconds);
const showSeconds = clockTimeFormatShowsSeconds(options.customTimeFormat);
const time = useCurrentTime({ showSeconds });
const requestedTimeZone = options.useCustomTimezone ? options.timezone : getResolvedLocalTimeZone();
const primaryTimeZoneInvalid = !isTimeZoneSupported(requestedTimeZone);
@@ -37,12 +37,7 @@ export default function ClockWidget({ options, width, height, displayMode }: Wid
return <Center h="100%">--:--</Center>;
}
const resolvedTimeFormat = resolveClockTimeFormat(
options.customTimeFormat,
options.is24HourFormat,
options.showSeconds,
);
const resolvedDateFormat = options.customDateFormat || options.dateFormat;
const resolvedTimeFormat = resolveClockTimeFormat(options.customTimeFormat, options.is24HourFormat);
const minimumAxis = Math.min(width, height * 1.5);
let sizing: "xs" | "sm" | "md" = "md";
if (minimumAxis < 128) sizing = "xs";
@@ -76,7 +71,7 @@ export default function ClockWidget({ options, width, height, displayMode }: Wid
</Title>
{options.showDate && (
<Text className="clock-date-text" size={sizing} lineClamp={1}>
{zonedTime?.format(resolvedDateFormat)}
{zonedTime?.format(options.dateFormat)}
</Text>
)}
</Stack>
+5 -5
View File
@@ -1,9 +1,9 @@
export const automaticTimeFormat = "automatic";
export const resolveClockTimeFormat = (format: string, legacyIs24HourFormat: boolean, showSeconds = false) => {
export const resolveClockTimeFormat = (format: string, legacyIs24HourFormat: boolean) => {
if (format && format !== automaticTimeFormat) return format;
if (legacyIs24HourFormat) return showSeconds ? "HH:mm:ss" : "HH:mm";
return showSeconds ? "hh:mm:ss A" : "hh:mm A";
if (legacyIs24HourFormat) return "HH:mm";
return "hh:mm A";
};
export const clockTimeFormatUses12Hours = (format: string, legacyIs24HourFormat: boolean) => {
@@ -12,8 +12,8 @@ export const clockTimeFormatUses12Hours = (format: string, legacyIs24HourFormat:
return /h{1,2}/.test(formatWithoutLiterals);
};
export const clockTimeFormatShowsSeconds = (format: string, showSeconds = false) => {
if (!format || format === automaticTimeFormat) return showSeconds;
export const clockTimeFormatShowsSeconds = (format: string) => {
if (!format || format === automaticTimeFormat) return false;
const formatWithoutLiterals = format.replace(/\[[^\]]*\]/g, "");
return /s{1,2}/.test(formatWithoutLiterals);
};
+11 -12
View File
@@ -46,9 +46,6 @@ export const { definition, componentLoader } = createWidgetDefinition("clock", {
defaultValue: true,
withDescription: true,
}),
showSeconds: factory.switch({
defaultValue: false,
}),
useCustomTimezone: factory.switch({ defaultValue: false }),
timezone: factory.select({
options: timeZoneOptions,
@@ -76,12 +73,14 @@ export const { definition, componentLoader } = createWidgetDefinition("clock", {
defaultValue: "dddd, MMMM D",
withDescription: true,
}),
customTimeFormat: factory.text({
defaultValue: "",
withDescription: true,
}),
customDateFormat: factory.text({
defaultValue: "",
customTimeFormat: factory.select({
options: [
{ value: "HH:mm", label: `${dayjs().format("HH:mm")} · HH:mm` },
{ value: "HH:mm:ss", label: `${dayjs().format("HH:mm:ss")} · HH:mm:ss` },
{ value: "h:mm A", label: `${dayjs().format("h:mm A")} · h:mm A` },
{ value: "h:mm:ss A", label: `${dayjs().format("h:mm:ss A")} · h:mm:ss A` },
],
defaultValue: "HH:mm",
withDescription: true,
}),
showWeather: factory.switch({
@@ -111,6 +110,9 @@ export const { definition, componentLoader } = createWidgetDefinition("clock", {
}),
}),
{
is24HourFormat: {
shouldHide: () => true,
},
customTitle: {
shouldHide: (options) => !options.customTitleToggle,
},
@@ -120,9 +122,6 @@ export const { definition, componentLoader } = createWidgetDefinition("clock", {
dateFormat: {
shouldHide: (options) => !options.showDate,
},
customDateFormat: {
shouldHide: (options) => !options.showDate,
},
weatherLocation: {
shouldHide: (options) => !options.showWeather,
},