From a337995a9dbcf1000679f9a2d086def0daa90b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 19 May 2020 17:06:44 +0200 Subject: Recurrence rules now always parsed. --- module/output/html.scm | 9 +++---- module/output/ical.scm | 9 ++----- module/vcomponent/parse/component.scm | 35 ++++++++++++++++++--------- module/vcomponent/recurrence/display/test.scm | 2 -- module/vcomponent/recurrence/generate-alt.scm | 5 ---- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/module/output/html.scm b/module/output/html.scm index da5c0659..b011da15 100644 --- a/module/output/html.scm +++ b/module/output/html.scm @@ -356,9 +356,8 @@ (define (format-recurrence-rule ev) `(span (@ (class "rrule")) "Upprepas " - ,((compose (@ (vcomponent recurrence display) format-recurrence-rule) - (@ (vcomponent recurrence parse) parse-recurrence-rule)) - (attr ev 'RRULE)) + ,((@ (vcomponent recurrence display) format-recurrence-rule) + (attr ev 'RRULE)) ,@(awhen (attr* ev 'EXDATE) (list ", undantaget " @@ -370,9 +369,7 @@ ;; NOTE only show time when it's different than the start time? ;; or possibly only when FREQ is hourly or lower. (if (memv ((@ (vcomponent recurrence internal) freq) - ((@ (vcomponent recurrence parse) - parse-recurrence-rule) - (attr ev 'RRULE))) + (attr ev 'RRULE)) '(HOURLY MINUTELY SECONDLY)) (datetime->string d "~e ~b ~k:~M") (datetime->string d "~e ~b")))) diff --git a/module/output/ical.scm b/module/output/ical.scm index e1da95ec..87a85f82 100644 --- a/module/output/ical.scm +++ b/module/output/ical.scm @@ -54,13 +54,8 @@ (modulo s 60)) )) [(RRULE) - ;; NOTE - ;; generated events are created with recur-rule objects. - ;; parsed objects keep their string representation. - ;; TODO normalize this. - (if ((@ (vcomponent recurrence internal) recur-rule?) value) - ((@ (vcomponent recurrence internal) recur-rule->rrule-string) value) - value)] + ((@ (vcomponent recurrence internal) + recur-rule->rrule-string) value)] (else (escape-chars value) diff --git a/module/vcomponent/parse/component.scm b/module/vcomponent/parse/component.scm index bb397f21..f8677a19 100644 --- a/module/vcomponent/parse/component.scm +++ b/module/vcomponent/parse/component.scm @@ -111,18 +111,29 @@ ;; TODO This is an ugly hack until the rest of the code is updated ;; to work on events without an explicit DTEND attribute. - (when (and (eq? (type (car stack)) 'VEVENT) - (not (attr (car stack) 'DTEND))) - (set! (attr (car stack) 'DTEND) - (let ((start (attr (car stack) 'DTSTART))) - ;; p. 54, 3.6.1 - ;; If DTSTART is a date then it's an all - ;; day event. If DTSTART instead is a - ;; datetime then the event has a length - ;; of 0? - (if (date? start) - (date+ start (date day: 1)) - (datetime+ start (datetime time: (time hour: 1))))))) + (when (eq? (type (car stack)) 'VEVENT) + (when (not (attr (car stack) 'DTEND)) + (set! (attr (car stack) 'DTEND) + (let ((start (attr (car stack) 'DTSTART))) + ;; p. 54, 3.6.1 + ;; If DTSTART is a date then it's an all + ;; day event. If DTSTART instead is a + ;; datetime then the event has a length + ;; of 0? + (if (date? start) + (date+ start (date day: 1)) + (datetime+ start (datetime time: (time hour: 1))))))) + + ;; This isn't part of the field values since we "need" + ;; the type of DTSTART for UNTIL to work. + ;; This could however be side steped by auto detecting + ;; @type{date}s vs @type{datetime}s in @function{parse-recurrence-rule}. + (when (attr (car stack) 'RRULE) + (set! (attr (car stack) 'RRULE) + ((@ (vcomponent recurrence) parse-recurrence-rule) + (attr (car stack) 'RRULE) + (if (date? (attr (car stack) 'DTSTART)) + parse-ics-date parse-ics-datetime))))) (loop (cdr lst) (if (null? (cdr stack)) diff --git a/module/vcomponent/recurrence/display/test.scm b/module/vcomponent/recurrence/display/test.scm index bcfbaafe..6c566499 100644 --- a/module/vcomponent/recurrence/display/test.scm +++ b/module/vcomponent/recurrence/display/test.scm @@ -25,8 +25,6 @@ (attr comp 'RRULE)) (map (lambda (d) (datetime->string d "~a ~1 ~3")) (stream->list - ;; TODO this assumes a future version of rrule-instances - ;; which assumes a pre parsed recurrence rule. 10 ((@@ (vcomponent recurrence generate-alt) rrule-instances) comp))))))) diff --git a/module/vcomponent/recurrence/generate-alt.scm b/module/vcomponent/recurrence/generate-alt.scm index 77304b55..1d32d793 100644 --- a/module/vcomponent/recurrence/generate-alt.scm +++ b/module/vcomponent/recurrence/generate-alt.scm @@ -332,11 +332,6 @@ rrule base-date))) (define-stream (rrule-instances event) - ;; (define rrule (parse-recurrence-rule - ;; (attr event 'RRULE) - ;; (if (date? (attr event 'DTSTART)) - ;; parse-ics-date parse-ics-datetime))) - (define rrule (attr event 'RRULE)) ;; 3.8.5.1 exdate are evaluated AFTER rrule (and rdate) -- cgit v1.2.3