diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-04-20 22:39:44 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-04-20 22:39:44 +0200 |
commit | 69b69306097b561b9c2c7dfeafd4aaff460b6fda (patch) | |
tree | 2bcc58172ad85739f84648e22631186b283fda27 /module/vcalendar/timezone.scm | |
parent | Add binding to dump vcomponent to stdout. (diff) | |
download | calp-timezone.tar.gz calp-timezone.tar.xz |
Add timezone handling.timezone
This is a way to large commit. But I see no feasable way to break it
down into multiple smaller commits.
The main "secret" to solving timezones for recurring events was to
remember to recalculate timezones whenever a new instance of the object
was generated.
This current implementation seems really slow (> 1s). Further testing is
needed.
Diffstat (limited to 'module/vcalendar/timezone.scm')
-rw-r--r-- | module/vcalendar/timezone.scm | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/module/vcalendar/timezone.scm b/module/vcalendar/timezone.scm index 82d13a8d..560289d4 100644 --- a/module/vcalendar/timezone.scm +++ b/module/vcalendar/timezone.scm @@ -6,7 +6,7 @@ :use-module (srfi srfi-41) :use-module (srfi srfi-41 util) :use-module (util) - :use-module ((vcalendar recur) :select (generate-recurrence-set)) + :use-module ((vcalendar recurrence generate) :select (generate-recurrence-set)) :use-module ((vcalendar datetime) :select (ev-time<?)) ) @@ -28,6 +28,16 @@ ;; : TZOFFSETFROM: +0200 ;; @end example +;; Given a tz stream of length 2, takes the time difference between the DTSTART +;; of those two. And creates a new VTIMEZONE with that end time. +;; TODO set remaining properties, and type of the newly created component. +(define (extrapolate-tz-stream strm) + (let ((nevent (copy-vcomponent (stream-ref strm 1)))) + (mod! (attr nevent 'DTSTART) + = (add-duration (time-difference + (attr (stream-ref strm 1) 'DTSTART) + (attr (stream-ref strm 0) 'DTSTART)))) + (stream-append strm (stream nevent)))) ;; The RFC requires that at least one DAYLIGHT or STANDARD component is present. ;; Any number of both can be present. This should handle all these cases well, @@ -39,9 +49,14 @@ ev-time<? ;; { DAYLIGHT, STANDARD } (map generate-recurrence-set (children tz))))) - (if (stream-null? strm) - stream-null - (stream-zip strm (stream-cdr strm))))) + + (cond [(stream-null? strm) stream-null] + + [(stream-null? (stream-drop 2 strm)) + (let ((strm (extrapolate-tz-stream strm))) + (stream-zip strm (stream-cdr strm)))] + + [else (stream-zip strm (stream-cdr strm))]))) (define (parse-offset str) (let* (((pm h1 h0 m1 m0) (string->list str))) |