aboutsummaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--expand-daily.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-16 15:22:48 -0500
committerCraig Jennings <c@cjennings.net>2026-07-16 15:22:48 -0500
commit2443d3da778b8ebccd33ee9a603c217ed069e340 (patch)
tree512ce2eef53ef1df61dfc6a8886e76aa3ddf8381 /tests/test-calendar-sync--expand-daily.el
parent7e0ac9d9fd2d7f539e07d785e4c26aa520513195 (diff)
downloaddotemacs-2443d3da778b8ebccd33ee9a603c217ed069e340.tar.gz
dotemacs-2443d3da778b8ebccd33ee9a603c217ed069e340.zip
fix(calendar-sync): keep the final occurrence of an UNTIL-bounded series
RFC 5545 3.3.10 bounds a recurrence inclusively: when UNTIL lines up with the recurrence, that date is the last instance. The expansion loops guarded on calendar-sync--before-date-p, a strict comparison, so the instance landing exactly on UNTIL was dropped. Every bounded series silently lost its last meeting from the agenda. A series whose UNTIL equals its start date lost the only instance it had and vanished. I added calendar-sync--date-on-or-before-p beside --before-date-p and swapped the three UNTIL sites: the simple-recurrence loop feeding daily, monthly and yearly, plus both weekly checks. --before-date-p is unchanged, since a date is still not before itself. The two UNTIL property tests asserted the wrong invariant. They required every occurrence to fall strictly before UNTIL, the exclusive reading the RFC contradicts, so they pinned the defect they should have caught. The property is now on-or-before. An upper bound alone can't catch a dropped occurrence, so I added one asserting the series reaches its UNTIL date. Reverting the fix failed three daily tests and one property test, and no weekly ones. The weekly loop was fixed but unguarded, so it has its own test now. The comparison stays date-granular, matching --date-to-time. An UNTIL carrying a time of day earlier than the event's start will include that final instance where the RFC would exclude it. Making it datetime-precise means reworking --date-to-time and the timezone conversions feeding it, a much larger change than this bug warrants.
Diffstat (limited to 'tests/test-calendar-sync--expand-daily.el')
-rw-r--r--tests/test-calendar-sync--expand-daily.el47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test-calendar-sync--expand-daily.el b/tests/test-calendar-sync--expand-daily.el
index 43b93664..0db9f345 100644
--- a/tests/test-calendar-sync--expand-daily.el
+++ b/tests/test-calendar-sync--expand-daily.el
@@ -176,5 +176,52 @@
(occurrences (calendar-sync--expand-daily base-event rrule range)))
(should (= (length occurrences) 5))))
+;;; UNTIL is inclusive (RFC 5545 3.3.10)
+
+(ert-deftest test-calendar-sync--expand-daily-until-includes-the-until-date ()
+ "Boundary: an occurrence falling ON the UNTIL date is kept.
+RFC 5545 3.3.10: UNTIL bounds the recurrence \"in an inclusive manner\", and
+when it lines up with the recurrence that date \"becomes the last instance\".
+A strict before-comparison drops it, so the last meeting of every bounded
+series silently vanishes from the agenda."
+ (let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
+ (until-date (test-calendar-sync-time-date-only 5))
+ (base-event (list :summary "Bounded Standup" :start start-date))
+ (rrule (list :freq 'daily :interval 1 :until until-date))
+ (range (test-calendar-sync-wide-range))
+ (occurrences (calendar-sync--expand-daily base-event rrule range))
+ (last-start (plist-get (car (last occurrences)) :start)))
+ ;; day+1 through day+5 inclusive = 5 occurrences.
+ (should (= (length occurrences) 5))
+ ;; The final occurrence is the UNTIL date itself.
+ (should (equal (seq-take last-start 3) until-date))))
+
+(ert-deftest test-calendar-sync--expand-daily-until-excludes-dates-after-it ()
+ "Boundary: inclusivity stops at UNTIL; the next day is not generated.
+Guards the fix against over-correcting into an off-by-one the other way."
+ (let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
+ (until-date (test-calendar-sync-time-date-only 5))
+ (day-after (test-calendar-sync-time-date-only 6))
+ (base-event (list :summary "Bounded Standup" :start start-date))
+ (rrule (list :freq 'daily :interval 1 :until until-date))
+ (range (test-calendar-sync-wide-range))
+ (occurrences (calendar-sync--expand-daily base-event rrule range))
+ (dates (mapcar (lambda (o) (seq-take (plist-get o :start) 3)) occurrences)))
+ (should (member until-date dates))
+ (should-not (member day-after dates))))
+
+(ert-deftest test-calendar-sync--expand-daily-until-on-start-date-yields-one ()
+ "Boundary: UNTIL equal to the start date yields exactly that one occurrence.
+The degenerate single-instance series -- a strict comparison returns nothing
+at all here, which is the same defect at its smallest."
+ (let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
+ (until-date (test-calendar-sync-time-date-only 1))
+ (base-event (list :summary "One Shot" :start start-date))
+ (rrule (list :freq 'daily :interval 1 :until until-date))
+ (range (test-calendar-sync-wide-range))
+ (occurrences (calendar-sync--expand-daily base-event rrule range)))
+ (should (= (length occurrences) 1))
+ (should (equal (seq-take (plist-get (car occurrences) :start) 3) until-date))))
+
(provide 'test-calendar-sync--expand-daily)
;;; test-calendar-sync--expand-daily.el ends here