aboutsummaryrefslogtreecommitdiff
path: root/module/vcalendar.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-04-06 19:08:59 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2019-04-13 00:14:55 +0200
commit59f6fc205b19f0cd2253adb7c656c4eda904a52e (patch)
tree2390a02195fdae3d79aa2b39d39e134c93871e3c /module/vcalendar.scm
parentRework how attributes and properties are accessed. (diff)
downloadcalp-59f6fc205b19f0cd2253adb7c656c4eda904a52e.tar.gz
calp-59f6fc205b19f0cd2253adb7c656c4eda904a52e.tar.xz
Add earlier work on timezones.
Add earlier work on timezones, with a few inline modifications. This is really to big of a commit. But we are so far from a stable release that it should be fine. The current version seems to eager, and recalculates to many times. This will soon be fixed in a future version.
Diffstat (limited to 'module/vcalendar.scm')
-rw-r--r--module/vcalendar.scm40
1 files changed, 36 insertions, 4 deletions
diff --git a/module/vcalendar.scm b/module/vcalendar.scm
index a4da1527..ef6fbd92 100644
--- a/module/vcalendar.scm
+++ b/module/vcalendar.scm
@@ -2,18 +2,50 @@
#:use-module (vcalendar primitive)
#:use-module (vcalendar datetime)
#:use-module (vcalendar recur)
+ #:use-module (vcalendar timezone)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-19)
+ #:use-module (srfi srfi-19 util)
#:use-module (srfi srfi-26)
#:use-module (util)
#:export (make-vcomponent)
#:re-export (repeating?))
+;; All VTIMEZONE's seem to be in "local" time in relation to
+;; themselves. Therefore, a simple comparison should work,
+;; and then the TZOFFSETTO attribute can be subtracted from
+;; the event DTSTART to get UTC time.
+
+(define string->time-utc
+ (compose date->time-utc (unval parse-datetime)))
+
(define (parse-dates! cal)
"Parse all start times into scheme date objects."
- (for-each-in (children cal 'VEVENT)
- (lambda (ev)
- (mod! (attr ev "DTSTART") parse-datetime)
- (mod! (attr ev "DTEND") parse-datetime)))
+
+ (for-each-in (children cal 'VTIMEZONE)
+ (lambda (tz)
+ (for-each (lambda (p) (mod! (attr p "DTSTART") string->time-utc))
+ (children tz))
+
+ ;; TZSET is the generated recurrence set of a timezone
+ (set! (attr tz 'X-HNH-TZSET)
+ (make-tz-set tz))))
+
+ (for-each
+ (lambda (ev)
+ (mod! (attr ev "DTSTART") string->time-utc
+ (attr ev "DTEND") string->time-utc)
+
+ (when (prop (attr* ev 'DTSTART) 'TZID)
+ (let* ((of (get-tz-offset ev)))
+ (set! (prop (attr* ev 'DTSTART) 'TZID) #f)
+ ;; 5545 says that DTEND is local time iff DTSTART is local time.
+ ;; But who says that will be true...
+ (mod! (attr ev 'DTSTART)
+ (cut subtract-duration <> (make-duration of))))))
+ (children cal 'VEVENT))
+
+ ;; Return
cal)