Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Calendar: all-day alerts ring at 9 AM, as Apple's do

Yashwanth Kamireddi540d1880aee1
diff --git a/.uiverify/calendar-alerts.mjs b/.uiverify/calendar-alerts.mjs
index f1e098d..a2562b7 100644
--- a/.uiverify/calendar-alerts.mjs
+++ b/.uiverify/calendar-alerts.mjs
@@ -33,5 +33,20 @@ await page.locator('input[placeholder="New Event"]').first().press("Enter");
await page.waitForTimeout(300);
sent = await page.evaluate(() => window.__eventSaves?.at(-1));
ok(sent && !("alerts" in sent), `an edit that leaves the alerts alone sends none ${JSON.stringify(Object.keys(sent ?? {}))}`);
+
+// An all-day event's alerts are Apple's: on the day or days before, each at 9 AM.
+await page.keyboard.press("Escape");
+await page.keyboard.press("Control+3");
+await page.waitForTimeout(300);
+await page.getByText("Flight to Hyderabad").first().click();
+await page.waitForTimeout(300);
+await page.getByRole("button", { name: "Alert", exact: true }).click();
+const offered = await page.getByRole("option").allInnerTexts();
+ok(offered.includes("On day of event (9 AM)") && offered.includes("1 week before (9 AM)"), `an all-day event offers Apple's 9 AM alerts ${JSON.stringify(offered)}`);
+await page.getByRole("option", { name: "1 day before (9 AM)" }).click();
+await page.locator('input[placeholder="New Event"]').first().press("Enter");
+await page.waitForTimeout(300);
+sent = await page.evaluate(() => window.__eventSaves?.at(-1));
+ok(JSON.stringify(sent?.alerts) === "[900]", `and rings at 9 AM the day before ${JSON.stringify(sent?.alerts)}`);
await b.close();
process.exitCode = failures ? 1 : 0;
diff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsx
index 214bb61..73ba80b 100644
--- a/src/screens/calendar/CalendarView.tsx
+++ b/src/screens/calendar/CalendarView.tsx
@@ -90,12 +90,15 @@ const ALERTS = [
{ minutes: 1440, label: "1 day before" },
{ minutes: 2880, label: "2 days before" },
];
+/** Apple's all-day alerts ring at 9 AM: minutes from the day's midnight, negative after it. */
const ALL_DAY_ALERTS = [
- { minutes: 0, label: "On day of event" },
- { minutes: 1440, label: "1 day before" },
- { minutes: 2880, label: "2 days before" },
- { minutes: 10080, label: "1 week before" },
+ { minutes: -540, label: "On day of event (9 AM)" },
+ { minutes: 900, label: "1 day before (9 AM)" },
+ { minutes: 2340, label: "2 days before (9 AM)" },
+ { minutes: 9540, label: "1 week before (9 AM)" },
];
+/** The midnight presets kept before, read as the 9 AM ones they meant. */
+const ALL_DAY_WAS: Record<number, number> = { 0: -540, 1440: 900, 2880: 2340, 10080: 9540 };
/** An alert Apple holds that no preset names — set on a phone, say. */
function alertLabel(m: number): string {
if (m === 0) return "At time of event";
@@ -473,7 +476,11 @@ export function CalendarView() {
setWeekNumbersState(on);
writeJson(WEEK_NUMBERS_KEY, on);
};
- const [defaultAlerts, setDefaultAlertsState] = useState<DefaultAlerts>(() => readJson(DEFAULT_ALERTS_KEY, { timed: {}, allDay: {} }));
+ const [defaultAlerts, setDefaultAlertsState] = useState<DefaultAlerts>(() => {
+ const kept = readJson<DefaultAlerts>(DEFAULT_ALERTS_KEY, { timed: {}, allDay: {} });
+ const allDay = Object.fromEntries(Object.entries(kept.allDay ?? {}).map(([g, m]) => [g, ALL_DAY_WAS[m] ?? m]));
+ return { timed: kept.timed ?? {}, allDay };
+ });
const setDefaultAlert = (kind: "timed" | "allDay", guid: string, minutes: number | null) =>
setDefaultAlertsState((was) => {
const next = { ...was, [kind]: { ...was[kind] } };