aboutsummaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync-properties.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-properties.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-properties.el')
-rw-r--r--tests/test-calendar-sync-properties.el40
1 files changed, 34 insertions, 6 deletions
diff --git a/tests/test-calendar-sync-properties.el b/tests/test-calendar-sync-properties.el
index c25bb99f..0b01cbd9 100644
--- a/tests/test-calendar-sync-properties.el
+++ b/tests/test-calendar-sync-properties.el
@@ -77,12 +77,21 @@ For any COUNT value N, expansion never produces more than N occurrences."
;;; Property 2: UNTIL Boundary
+;; These two asserted the wrong invariant until 2026-07-16: they required every
+;; occurrence to fall strictly BEFORE UNTIL, which is the exclusive reading RFC
+;; 5545 3.3.10 contradicts ("bounds the recurrence rule in an inclusive manner";
+;; a UNTIL synchronized with the recurrence "becomes the last instance"). They
+;; were written against the expansion loop's strict `before-date-p' guard and so
+;; pinned the very defect that dropped the last instance of every bounded series.
+;; The property is on-or-before; the upper bound is what UNTIL is for.
+
(ert-deftest test-calendar-sync-property-until-bounds-daily ()
- "Property: No daily occurrence starts on or after UNTIL date."
+ "Property: no daily occurrence starts after the UNTIL date.
+UNTIL is an inclusive bound (RFC 5545 3.3.10), so landing exactly on it is
+correct and only a later date violates the property."
(dotimes (_ test-calendar-sync-property-trials)
(let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
(until-days (+ 10 (random 60)))
- ;; UNTIL must be date-only (3 elements) for calendar-sync--before-date-p
(until-date (test-calendar-sync-time-date-only until-days))
(base-event (list :summary "Until Test" :start start-date))
(rrule (list :freq 'daily :interval 1 :until until-date))
@@ -90,16 +99,35 @@ For any COUNT value N, expansion never produces more than N occurrences."
(occurrences (calendar-sync--expand-daily base-event rrule range)))
(dolist (occ occurrences)
(let ((occ-start (plist-get occ :start)))
- (should (calendar-sync--before-date-p
+ (should (calendar-sync--date-on-or-before-p
(list (nth 0 occ-start) (nth 1 occ-start) (nth 2 occ-start))
until-date)))))))
+(ert-deftest test-calendar-sync-property-until-bounds-daily-reaches-until ()
+ "Property: a daily series stepping by one day always reaches its UNTIL date.
+With interval 1 the recurrence is synchronized with any UNTIL, so the last
+instance must be UNTIL itself. This is the half the old exclusive property
+could never have caught -- it only bounded from above, so silently dropping
+the final occurrence satisfied it."
+ (dotimes (_ test-calendar-sync-property-trials)
+ (let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
+ (until-days (+ 10 (random 60)))
+ (until-date (test-calendar-sync-time-date-only until-days))
+ (base-event (list :summary "Until Test" :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)))
+ (should occurrences)
+ (should (equal (seq-take last-start 3) until-date)))))
+
(ert-deftest test-calendar-sync-property-until-bounds-weekly ()
- "Property: No weekly occurrence starts on or after UNTIL date."
+ "Property: no weekly occurrence starts after the UNTIL date.
+UNTIL is an inclusive bound (RFC 5545 3.3.10), so landing exactly on it is
+correct and only a later date violates the property."
(dotimes (_ test-calendar-sync-property-trials)
(let* ((start-date (test-calendar-sync-time-days-from-now 1 10 0))
(until-days (+ 14 (random 60)))
- ;; UNTIL must be date-only (3 elements) for calendar-sync--before-date-p
(until-date (test-calendar-sync-time-date-only until-days))
(weekdays (test-calendar-sync-random-weekday-subset))
(base-event (list :summary "Until Test" :start start-date))
@@ -108,7 +136,7 @@ For any COUNT value N, expansion never produces more than N occurrences."
(occurrences (calendar-sync--expand-weekly base-event rrule range)))
(dolist (occ occurrences)
(let ((occ-start (plist-get occ :start)))
- (should (calendar-sync--before-date-p
+ (should (calendar-sync--date-on-or-before-p
(list (nth 0 occ-start) (nth 1 occ-start) (nth 2 occ-start))
until-date)))))))