aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/island/calendar/Cal.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-13 09:17:23 +0100
committerDanilo M. <danix@danix.xyz>2026-11-13 09:17:23 +0100
commit9c47ad7c10aa5a04de738a5d41acc01cc0e5e059 (patch)
tree98ad93b89243f776aab782e35419a2ad7b8ee736 /desktop/island/calendar/Cal.js
parentfda4e7847bb5dc985404269c81400eead52b0181 (diff)
downloadquickshell-9c47ad7c10aa5a04de738a5d41acc01cc0e5e059.tar.gz
quickshell-9c47ad7c10aa5a04de738a5d41acc01cc0e5e059.zip
feat(calendar): click-to-pick event times, loose time typing
The month grid was already the editor's date picker, but times could only be typed or wheeled. While a time field has focus the month now gives way to an hour grid and a :00/:15/:30/:45 row: an hour keeps the minutes, a minute moves on from start to end, then out of the fields. The picker replaces the grid rather than growing the editor, because the island's layer surface is a fixed 480px and the editor nearly fills it. The field keeps focus throughout, so typing and the wheel still work. Typed times are normalised: "9.30", "9:30", "930", "9" and "14h15" become HH:MM on leaving the field and again in toPayload, instead of failing with "Times are HH:MM". Impossible values still fail, unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/island/calendar/Cal.js')
-rw-r--r--desktop/island/calendar/Cal.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/desktop/island/calendar/Cal.js b/desktop/island/calendar/Cal.js
index d8dcf80..6cf492d 100644
--- a/desktop/island/calendar/Cal.js
+++ b/desktop/island/calendar/Cal.js
@@ -94,9 +94,19 @@ function validTime(s) {
return /^([01]\d|2[0-3]):[0-5]\d$/.test(s);
}
+// Loose typing as HH:MM: "9.30", "9:30", "930" and "9" mean what they look
+// like. Anything else comes back unchanged, for validTime to reject.
+function normTime(s) {
+ const m = /^\s*(\d{1,2})(?:[:.,h ]?(\d{2}))?\s*$/.exec(s);
+ if (!m) return s;
+ const t = pad(+m[1]) + ":" + (m[2] || "00");
+ return validTime(t) ? t : s;
+}
+
// Step a time by minutes, wrapping within the day; an invalid time is left
// for the user to fix rather than guessed at.
function stepTime(s, minutes) {
+ s = normTime(s);
if (!validTime(s)) return s;
const m = ((+s.slice(0, 2) * 60 + +s.slice(3, 5) + minutes) % 1440 + 1440) % 1440;
return pad(Math.floor(m / 60)) + ":" + pad(m % 60);
@@ -141,6 +151,7 @@ function pick(draft, day, shift) {
// The draft as calctl's event JSON, or the first thing wrong with it.
function toPayload(d) {
+ d = Object.assign({}, d, { startTime: normTime(d.startTime), endTime: normTime(d.endTime) });
if (!d.title.trim()) return { error: "Title is empty" };
if (!d.allDay && (!validTime(d.startTime) || !validTime(d.endTime)))
return { error: "Times are HH:MM" };