From 88e14917882b0c3f79e942b61027882fe9a7fe87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 24 May 2020 22:31:08 +0200 Subject: Handle events with no DTEND. --- module/output/html.scm | 20 +++++--- module/vcomponent/datetime.scm | 86 +++++++++++++++++++++-------------- module/vcomponent/group.scm | 6 ++- module/vcomponent/parse/component.scm | 13 ------ static/style.css | 9 ++++ 5 files changed, 80 insertions(+), 54 deletions(-) diff --git a/module/output/html.scm b/module/output/html.scm index 64859c2d..8ca831f0 100644 --- a/module/output/html.scm +++ b/module/output/html.scm @@ -97,10 +97,12 @@ [else ; guaranteed datetime (let ((s (attr ev 'DTSTART)) (e (attr ev 'DTEND))) - (let ((fmt-str (if (date= (get-date s) (get-date e)) - "~H:~M" "~Y-~m-~d ~H:~M"))) - (values (datetime->string s fmt-str) - (datetime->string e fmt-str))))])) + (if e + (let ((fmt-str (if (date= (get-date s) (get-date e)) + "~H:~M" "~Y-~m-~d ~H:~M"))) + (values (datetime->string s fmt-str) + (datetime->string e fmt-str))) + (datetime->string s "~Y-~m-~d ~H:~M")))])) @@ -241,7 +243,7 @@ ev `((class ,(when (datelist events))) + (zero-length-events short-events + (partition event-zero-length? (stream->list events)))) (fix-event-widths! short-events event-length-key: (lambda (e) (event-length/day day-date e))) @@ -301,6 +305,8 @@ ,@(map (lambda (time) `(div (@ (class "clock clock-" ,time)) "")) (iota 12 0 2)) + (div (@ (class "zero-width-events")) + ,(map make-block zero-length-events)) ,@(map (lambda (e) (create-block day-date e)) short-events)))) diff --git a/module/vcomponent/datetime.scm b/module/vcomponent/datetime.scm index 28d48361..057b9ca1 100644 --- a/module/vcomponent/datetime.scm +++ b/module/vcomponent/datetime.scm @@ -29,14 +29,20 @@ "Returns if the event overlaps the timespan. Event must have the DTSTART and DTEND attribute set." (timespan-overlaps? (attr event 'DTSTART) - (attr event 'DTEND) + (or (attr event 'DTEND) (attr event 'DTSTART)) begin end)) (define (overlapping? event-a event-b) (timespan-overlaps? (attr event-a 'DTSTART) - (attr event-a 'DTEND) + (or (attr event-a 'DTEND) + (if (date? (attr event-a 'DTSTART)) + (date+ (attr event-a 'DTSTART) (date day: 1)) + (attr event-a 'DTSTART))) (attr event-b 'DTSTART) - (attr event-b 'DTEND))) + (or (attr event-b 'DTEND) + (if (date? (attr event-b 'DTSTART)) + (date+ (attr event-b 'DTSTART) (date day: 1)) + (attr event-b 'DTSTART))))) (define (event-contains? ev date/-time) "Does event overlap the date that contains time." @@ -44,6 +50,10 @@ Event must have the DTSTART and DTEND attribute set." (end (add-day start))) (event-overlaps? ev start end))) +(define-public (event-zero-length? ev) + (and (datetime? (attr ev 'DTSTART)) + (not (attr ev 'DTEND)))) + (define-public (ev-timesymbol (cadr head))) stack))] [(string=? "END" (car head)) - ;; TODO This is an ugly hack until the rest of the code is updated - ;; to work on events without an explicit DTEND attribute. (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. diff --git a/static/style.css b/static/style.css index 875adc18..9b680a52 100644 --- a/static/style.css +++ b/static/style.css @@ -499,6 +499,15 @@ along with their colors. width: 100%; } +.zero-width-events .event { + width: initial; + padding: 0.5em; + margin: 0.2em; + border-radius: 1ex; + position: relative; + float: left; +} + .events .event.continuing { border-bottom: none; background-image: linear-gradient(to top, #0007 0%,#FFF0 2em); -- cgit v1.2.3