From 9d471cd6cdd182c01bb6d7a7c7e0318a2daa3372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 29 Mar 2020 23:25:20 +0200 Subject: Clarify error on bad RRULE's. --- module/datetime.scm | 4 ++-- module/vcomponent/recurrence/generate.scm | 11 ++++++----- module/vcomponent/recurrence/parse.scm | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'module') diff --git a/module/datetime.scm b/module/datetime.scm index f7455501..4fef907f 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -667,9 +667,9 @@ minute: (s->n str 2 4) second: (s->n str 4 6))) -;;; TODO when parsing recurrence rules sometimes I think this is -;;; sent regular dates (define*-public (parse-datetime str optional: tz) + (unless (string-any #\T str) + (throw 'parse-error "String ~a doesn't look like a valid datetime" str)) (let* (((datestr timestr) (string-split str #\T))) (datetime date: (parse-date datestr) time: (parse-time timestr) diff --git a/module/vcomponent/recurrence/generate.scm b/module/vcomponent/recurrence/generate.scm index ce64e741..ee59ed04 100644 --- a/module/vcomponent/recurrence/generate.scm +++ b/module/vcomponent/recurrence/generate.scm @@ -120,7 +120,7 @@ ((e r) (or (and (not (until r)) (not (count r))) ; Never ending (and=> (count r) (negate zero?)) ; COUNT - (and=> (until r) (lambda (dt) ((if (date? dt) date<= date/-time<=) ; UNTIL + (and=> (until r) (lambda (dt) ((if (date? dt) date<= datetime<=) ; UNTIL (attr e 'DTSTART) dt)))))) ;; Event x Rule → next (Event, Rule) @@ -155,10 +155,11 @@ (date-difference end (attr event 'DTSTART)) (datetime-difference end (attr event 'DTSTART))))])) (if (attr event "RRULE") - (recur-event-stream event (parse-recurrence-rule - (attr event "RRULE") - (if (eq? 'DATE (and=> (prop (attr* event 'DTSTART) 'VALUE) car)) - parse-date parse-datetime))) + (recur-event-stream + event (parse-recurrence-rule + (attr event "RRULE") + (if (date? (attr event 'DTSTART)) + parse-date parse-datetime))) ;; TODO some events STANDARD and DAYLIGT doesn't have RRULE's, but rather ;; just mention the current part. Handle this stream-null)))) diff --git a/module/vcomponent/recurrence/parse.scm b/module/vcomponent/recurrence/parse.scm index a93b81df..97e5e980 100644 --- a/module/vcomponent/recurrence/parse.scm +++ b/module/vcomponent/recurrence/parse.scm @@ -48,8 +48,9 @@ `(else ,@body))) cases)))) -;; UNTIL must have the exact same value type as the DTSTART of the event from which -;; this string came. I have however seen exceptions to that rule... +;; RFC 5545, Section 3.3.10. Recurrence Rule, states that the UNTIL value MUST have +;; the same type as the DTSTART of the event (date or datetime). I have seen events +;; in the wild which didn't follow this. I consider that an user error. (define* (parse-recurrence-rule str optional: (datetime-parser parse-datetime)) (fold (lambda (kv o) -- cgit v1.2.3