diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 13:08:29 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 13:08:29 -0500 |
| commit | 2ee215e1f948f3ac398f46bb995ac94ec3ce3a61 (patch) | |
| tree | 6164c9415d01d4e2002d123eb20edfb35ce80c4e | |
| parent | d09da430bf1fa08bb089b4386b6284879088260b (diff) | |
| download | chime-2ee215e1f948f3ac398f46bb995ac94ec3ce3a61.tar.gz chime-2ee215e1f948f3ac398f46bb995ac94ec3ce3a61.zip | |
Extract days-until calculation from chime--day-wide-notification-text
Move the all-day timestamp date arithmetic into chime--days-until-event.
The notification text function now reads clearly as a cond dispatch
over today/advance-notice/fallback cases.
| -rw-r--r-- | chime.el | 49 |
1 files changed, 22 insertions, 27 deletions
@@ -880,45 +880,40 @@ For timed events, checks if the time is today (past or future)." (time-equal-p event-date today-start))))) (cdr (assoc 'times event)))) +(defun chime--days-until-event (all-times) + "Calculate minimum days until the soonest all-day timestamp in ALL-TIMES. +ALL-TIMES is a list of (TIMESTAMP-STR . TIME-OBJECT) cons cells. +Returns integer days (ceiling), or nil if no all-day timestamps found." + (let ((now (current-time))) + (-min + (--map + (when-let* ((timestamp-str (car it)) + (is-all-day (not (chime--has-timestamp timestamp-str))) + (parsed (org-parse-time-string timestamp-str)) + (year (nth 5 parsed)) + (month (nth 4 parsed)) + (day (nth 3 parsed))) + (let* ((event-time (encode-time 0 0 0 day month year)) + (seconds-until (time-subtract event-time now))) + (ceiling (/ (float-time seconds-until) 86400.0)))) + all-times)))) + (defun chime--day-wide-notification-text (event) "Generate notification text for day-wide EVENT. Handles both same-day events and advance notices." (let* ((title (cdr (assoc 'title event))) - (all-times (cdr (assoc 'times event))) (is-today (chime-event-has-any-passed-time event)) (is-advance-notice (and chime-day-wide-advance-notice (chime-event-within-advance-notice-window event)))) (cond - ;; Event is today (is-today (format "%s is due or scheduled today" title)) - ;; Event is within advance notice window (is-advance-notice - ;; Calculate days until event - (let* ((now (current-time)) - (days-until - (-min - (--map - (when-let* ((timestamp-str (car it)) - (is-all-day (not (chime--has-timestamp timestamp-str))) - (parsed (org-parse-time-string timestamp-str)) - - (year (nth 5 parsed)) - (month (nth 4 parsed)) - (day (nth 3 parsed))) - (let* ((event-time (encode-time 0 0 0 day month year)) - (seconds-until (time-subtract event-time now)) - (days (/ (float-time seconds-until) 86400.0))) - (ceiling days))) - all-times)))) + (let ((days-until (chime--days-until-event (cdr (assoc 'times event))))) (cond - ((= days-until 1) - (format "%s is tomorrow" title)) - ((= days-until 2) - (format "%s is in 2 days" title)) - (t - (format "%s is in %d days" title days-until))))) - ;; Fallback (shouldn't happen) + ((= days-until 1) (format "%s is tomorrow" title)) + ((= days-until 2) (format "%s is in 2 days" title)) + (t (format "%s is in %d days" title days-until))))) (t (format "%s is due or scheduled today" title))))) |
