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.

Times typed as said — '930', '9:30', '4:30pm', 'noon' — and stepped by the arrows, fifteen minutes or an hour with Shift, in Calendar and Reminders; Linux's segmented time input replaced

Yashwanth Kamireddi3497f1016239
diff --git a/.uiverify/calendar-keys.mjs b/.uiverify/calendar-keys.mjs
index 3f573e2..fba2576 100644
--- a/.uiverify/calendar-keys.mjs
+++ b/.uiverify/calendar-keys.mjs
@@ -38,5 +38,20 @@ await page.waitForTimeout(300);
const sent = await page.evaluate(() => window.__nudges);
ok(sent.length === 1 && sent[0].guid === "e1" && (sent[0].startsAt % 3600) === 900,
`Ctrl+Option+Down moves the event 15 minutes later ${JSON.stringify(sent.map((d) => d.startsAt % 3600))}`);
+// A time is typed as said, and stepped with the arrows.
+await page.keyboard.press("Escape");
+await page.waitForTimeout(200);
+await page.evaluate(() => { window.__nudges = []; });
+await page.locator(".cx-block", { hasText: "Design review" }).first().click();
+await page.waitForTimeout(250);
+const start = page.getByLabel(/^Starts time$/i).first();
+await start.fill("4:30pm");
+await start.press("Enter");
+await page.waitForTimeout(150);
+const typed = await start.inputValue();
+ok(/4:30/.test(typed) && /PM|16/i.test(typed), `"4:30pm" typed into a time is read [${typed}]`);
+await start.press("ArrowUp");
+await page.waitForTimeout(150);
+ok(/4:45/.test(await start.inputValue()), `the arrows step it fifteen minutes [${await start.inputValue()}]`);
await b.close();
process.exitCode = failures ? 1 : 0;
diff --git a/.uiverify/calendar.mjs b/.uiverify/calendar.mjs
index 1c1a22f..86d05c3 100644
--- a/.uiverify/calendar.mjs
+++ b/.uiverify/calendar.mjs
@@ -131,7 +131,7 @@ ok(/Sep/.test(title) && /Oct/.test(title), `a week across two months is named fo
const covers = made.pop && made.block && made.pop[0] < made.block[1] && made.pop[1] > made.block[0]
&& made.pop[2] < made.block[3] && made.pop[3] > made.block[2];
ok(!covers, "the popover sits beside the new event, not over it", `the popover covers it: ${JSON.stringify(made)}`);
- const fields = await page.locator(".cx-popover .cx-when input").evaluateAll((els) => els.map((e) => e.type));
+ const fields = await page.locator(".cx-popover .cx-when input").evaluateAll((els) => els.map((e) => (e.classList.contains("time-field") ? "time" : e.type)));
ok(JSON.stringify(fields) === JSON.stringify(["date", "time", "date", "time"]),
"a start and an end, each a date and a time", `the popover's fields are ${JSON.stringify(fields)}`);
await page.keyboard.press("Escape");
diff --git a/src/components/TimeField.tsx b/src/components/TimeField.tsx
new file mode 100644
index 0000000..2be31e7
--- /dev/null
+++ b/src/components/TimeField.tsx
@@ -0,0 +1,118 @@
+import { useEffect, useState } from "react";
+
+/**
+ * A time of day, typed as a person says it — "9", "930", "9:30", "9.30pm", "21:15",
+ * "noon" — and stepped with the arrows, fifteen minutes a press, an hour with Shift, as
+ * macOS's time fields step. Shown in this machine's own clock, 12- or 24-hour.
+ *
+ * Linux's built-in time input is a row of tiny segments that each want their own keys: it
+ * was where people gave up changing an event's time. A plain field takes what is typed and
+ * keeps the last good time if it cannot read it.
+ */
+export function TimeField({
+ hours,
+ minutes,
+ onChange,
+ label,
+ disabled = false,
+ className = "",
+}: {
+ hours: number;
+ minutes: number;
+ onChange: (hours: number, minutes: number) => void;
+ label: string;
+ disabled?: boolean;
+ className?: string;
+}) {
+ const shown = formatTime(hours, minutes);
+ const [text, setText] = useState(shown);
+ useEffect(() => setText(shown), [shown]);
+
+ const commit = () => {
+ const parsed = parseTime(text);
+ if (parsed && (parsed[0] !== hours || parsed[1] !== minutes)) onChange(parsed[0], parsed[1]);
+ else setText(shown);
+ };
+ const step = (by: number) => {
+ const total = (((hours * 60 + minutes + by) % 1440) + 1440) % 1440;
+ onChange(Math.floor(total / 60), total % 60);
+ };
+
+ return (
+ <input
+ type="text"
+ inputMode="text"
+ className={`time-field ${className}`.trim()}
+ aria-label={label}
+ value={text}
+ disabled={disabled}
+ readOnly={disabled}
+ spellCheck={false}
+ autoComplete="off"
+ onChange={(e) => setText(e.target.value)}
+ onFocus={(e) => e.currentTarget.select()}
+ onBlur={commit}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ commit();
+ } else if (e.key === "Escape") {
+ setText(shown);
+ } else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
+ e.preventDefault();
+ step((e.key === "ArrowUp" ? 1 : -1) * (e.shiftKey ? 60 : 15));
+ }
+ }}
+ />
+ );
+}
+
+const usesTwelveHour = (() => {
+ try {
+ return new Intl.DateTimeFormat(undefined, { hour: "numeric" }).resolvedOptions().hour12 ?? false;
+ } catch {
+ return false;
+ }
+})();
+
+export function formatTime(hours: number, minutes: number): string {
+ const d = new Date(2000, 0, 1, hours, minutes);
+ return d.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
+}
+
+/** `[hours, minutes]`, or null when the text is not a time. */
+export function parseTime(raw: string): [number, number] | null {
+ const t = raw.trim().toLowerCase().replace(/\s+/g, " ");
+ if (!t) return null;
+ if (t === "noon") return [12, 0];
+ if (t === "midnight") return [0, 0];
+ const m = t.match(/^(\d{1,2})(?:[:.h ]?(\d{2}))?\s*(a|am|a\.m\.|p|pm|p\.m\.)?$/);
+ const compact = t.match(/^(\d{3,4})\s*(a|am|p|pm)?$/);
+ let h: number;
+ let min: number;
+ let mer: string | undefined;
+ if (compact && !m?.[2]) {
+ const digits = compact[1];
+ h = Number(digits.slice(0, digits.length - 2));
+ min = Number(digits.slice(-2));
+ mer = compact[2];
+ } else if (m) {
+ h = Number(m[1]);
+ min = m[2] ? Number(m[2]) : 0;
+ mer = m[3];
+ } else {
+ return null;
+ }
+ if (min > 59) return null;
+ if (mer) {
+ if (h < 1 || h > 12) return null;
+ const pm = mer.startsWith("p");
+ h = (h % 12) + (pm ? 12 : 0);
+ } else if (h > 23) {
+ return null;
+ } else if (usesTwelveHour && h >= 1 && h <= 7) {
+ // "3" in a 12-hour clock means the afternoon, as macOS reads it for an event.
+ h += 12;
+ }
+ return [h, min];
+}
diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsx
index 4c8a22d..543b77c 100644
--- a/src/screens/RemindersView.tsx
+++ b/src/screens/RemindersView.tsx
@@ -1,6 +1,7 @@
import { Fragment, useCallback, useEffect, useMemo, useState } from "react";
import { Notice } from "../components/Notice";
import { Portal } from "../components/Portal";
+import { TimeField } from "../components/TimeField";
import { ChevronLeft } from "lucide-react";
import {
api,
@@ -1360,13 +1361,12 @@ function DueField({ reminder, onChange }: { reminder: Reminder; onChange: (day:
/>
<span>Time</span>
</label>
- {time !== null && (
- <input
- type="time"
- aria-label={`Time of day for ${reminder.title}`}
- defaultValue={time}
- key={`t${reminder.dueAt}`}
- onBlur={(e) => e.target.value && e.target.value !== time && onChange(day, e.target.value)}
+ {time !== null && at && (
+ <TimeField
+ label={`Time of day for ${reminder.title}`}
+ hours={at.getHours()}
+ minutes={at.getMinutes()}
+ onChange={(h, m) => onChange(day, `${pad(h)}:${pad(m)}`)}
/>
)}
</div>
diff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsx
index 5f9bd69..ddca77c 100644
--- a/src/screens/calendar/CalendarView.tsx
+++ b/src/screens/calendar/CalendarView.tsx
@@ -1,5 +1,6 @@
import { Notice } from "../../components/Notice";
import { Portal } from "../../components/Portal";
+import { TimeField } from "../../components/TimeField";
import { Search } from "lucide-react";
import { createContext, Fragment, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import {
@@ -1497,13 +1498,12 @@ function When({
onChange={(e) => e.target.value && onChange(fromLocalInput(`${e.target.value}T${time}`))}
/>
{!allDay && (
- <input
- type="time"
- aria-label={`${label} time`}
- step={300}
- value={time}
- readOnly={!editable}
- onChange={(e) => e.target.value && onChange(fromLocalInput(`${day}T${e.target.value}`))}
+ <TimeField
+ label={`${label} time`}
+ hours={d.getHours()}
+ minutes={d.getMinutes()}
+ disabled={!editable}
+ onChange={(h, m) => onChange(fromLocalInput(`${day}T${pad(h)}:${pad(m)}`))}
/>
)}
</span>
diff --git a/src/styles/app.css b/src/styles/app.css
index d8ea8a8..c67ae59 100644
--- a/src/styles/app.css
+++ b/src/styles/app.css
@@ -1775,3 +1775,5 @@
/* On the selection's blue an icon turns white, as Finder's do; a blue folder on blue vanished. */
.drive-rows:not(.is-grid) .drive-row.is-selected .drive-badge > svg { filter: brightness(0) invert(1); }
.drive-row.is-selected .drive-more { color: #fff; }
+/* A time typed as said: the width of "12:45 PM", right-aligned figures, as macOS's. */
+.time-field { width: 8.5ch; text-align: center; font-variant-numeric: tabular-nums; }