diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-16 15:41:48 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-16 15:41:48 -0500 |
| commit | 5803bab70d4b6298877bd8c8b96b0813e875f1c0 (patch) | |
| tree | a4cc56dc17b097c39dd1b896997ba5596a260fbe /tests/test-calendar-sync--format-timestamp.el | |
| parent | 2443d3da778b8ebccd33ee9a603c217ed069e340 (diff) | |
| download | dotemacs-5803bab70d4b6298877bd8c8b96b0813e875f1c0.tar.gz dotemacs-5803bab70d4b6298877bd8c8b96b0813e875f1c0.zip | |
fix(calendar-sync): render multi-day events as org ranges
format-timestamp built its date from the start and took only the hour and
minute from the end, so the end date was thrown away. A conference running Jul
20 09:00 to Jul 23 17:00 produced <2026-07-20 Mon 09:00-17:00>, byte for byte
the same timestamp as a same-day meeting, and the agenda showed it on the first
day only. All-day spans collapsed the same way, to a bare <2026-07-20 Mon>.
An event whose last day is later than its start now renders as an org range,
<start>--<end>, which org parses as an active-range and shows on every day it
covers.
DTEND is the non-inclusive end of the event (RFC 5545 3.6.1), so an all-day
event's last day is DTEND-1. Getting that backwards would have been worse than
the bug: a one-day all-day event carries DTEND = start+1, so a naive range
would turn every single all-day event into a two-day one. The decrement only
applies when both ends are date-only. A date-only start with a timed end is
malformed, and treating it as all-day would put the last day before the start
and emit a backwards range. That case falls through to the same-day form, as
before.
I split out format-stamp and format-hhmm so both halves of a range and the
compact same-day form build from one place.
Same-day events are unchanged, pinned by two tests: the compact HH:MM-HH:MM
form, and a single all-day event staying a single stamp.
One unrelated bug stays open. A timed event with no DTEND renders as <date> and
drops its time, so a 09:00 meeting reads as all-day. I left it alone.
Diffstat (limited to 'tests/test-calendar-sync--format-timestamp.el')
| -rw-r--r-- | tests/test-calendar-sync--format-timestamp.el | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test-calendar-sync--format-timestamp.el b/tests/test-calendar-sync--format-timestamp.el index 5b8a6d02..b84e625d 100644 --- a/tests/test-calendar-sync--format-timestamp.el +++ b/tests/test-calendar-sync--format-timestamp.el @@ -56,5 +56,59 @@ ;; start-hour is nil so time-str should be nil (should-not (string-match-p "[0-9][0-9]:[0-9][0-9]-" result)))) +;;; Multi-day spans (org range syntax) + +(ert-deftest test-calendar-sync--format-timestamp-multi-day-timed-spans-dates () + "A timed event ending on a later date renders as an org range. +The end DATE used to be discarded and only its time kept, so a four-day +conference produced the same timestamp as a same-day meeting and the agenda +showed it on day one only." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 14 0) '(2026 3 18 15 30)))) + (should (equal result "<2026-03-15 Sun 14:00>--<2026-03-18 Wed 15:30>")))) + +(ert-deftest test-calendar-sync--format-timestamp-multi-day-all-day-excludes-dtend () + "An all-day span ends the day before DTEND, which is non-inclusive. +RFC 5545 3.6.1: DTEND is \"the non-inclusive end of the event\", so an +all-day event running Mar 15-17 carries DTEND 2026-03-18. Rendering DTEND +verbatim would add a phantom fourth day." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 nil nil) '(2026 3 18 nil nil)))) + (should (equal result "<2026-03-15 Sun>--<2026-03-17 Tue>")))) + +(ert-deftest test-calendar-sync--format-timestamp-single-all-day-stays-single () + "A one-day all-day event stays a single stamp, never a degenerate range. +Its DTEND is the next day (non-inclusive), so a naive range would turn every +single all-day event into a two-day one -- a worse regression than the +collapse this range support fixes." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 nil nil) '(2026 3 16 nil nil)))) + (should (equal result "<2026-03-15 Sun>")) + (should-not (string-match-p "--" result)))) + +(ert-deftest test-calendar-sync--format-timestamp-same-day-timed-stays-compact () + "A same-day timed event keeps the compact HH:MM-HH:MM form, not a range. +Guards the common case against the range branch." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 14 0) '(2026 3 15 15 30)))) + (should (equal result "<2026-03-15 Sun 14:00-15:30>")) + (should-not (string-match-p "--" result)))) + +(ert-deftest test-calendar-sync--format-timestamp-multi-day-all-day-two-days () + "Boundary: the shortest real all-day span (two days) renders as a range. +DTEND 2026-03-17 means the event covers Mar 15-16; one day fewer and it +collapses to the single-stamp case above." + (let ((result (calendar-sync--format-timestamp + '(2026 3 15 nil nil) '(2026 3 17 nil nil)))) + (should (equal result "<2026-03-15 Sun>--<2026-03-16 Mon>")))) + +(ert-deftest test-calendar-sync--format-timestamp-multi-day-span-crosses-month () + "Boundary: an all-day span crossing a month boundary decrements correctly. +DTEND 2026-04-01 means the event's last day is 2026-03-31, which exercises +the borrow in `calendar-sync--add-days'." + (let ((result (calendar-sync--format-timestamp + '(2026 3 30 nil nil) '(2026 4 1 nil nil)))) + (should (equal result "<2026-03-30 Mon>--<2026-03-31 Tue>")))) + (provide 'test-calendar-sync--format-timestamp) ;;; test-calendar-sync--format-timestamp.el ends here |
