aboutsummaryrefslogtreecommitdiff
path: root/module/vcalendar/datetime.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/vcalendar/datetime.scm')
-rw-r--r--module/vcalendar/datetime.scm34
1 files changed, 34 insertions, 0 deletions
diff --git a/module/vcalendar/datetime.scm b/module/vcalendar/datetime.scm
new file mode 100644
index 00000000..360b8348
--- /dev/null
+++ b/module/vcalendar/datetime.scm
@@ -0,0 +1,34 @@
+(define-module (vcalendar datetime)
+ #:use-module (vcalendar)
+ #:use-module (srfi srfi-19)
+ #:use-module (srfi srfi-19 util)
+
+ #:export (parse-datetime
+ event-overlaps?
+ event-in?)
+ )
+
+(define (parse-datetime dtime)
+ "Parse the given date[time] string into a date object."
+ ;; localize-date
+ (date->time-utc
+ (string->date
+ dtime
+ (case (string-length dtime)
+ ((8) "~Y~m~d")
+ ((15) "~Y~m~dT~H~M~S")
+ ((16) "~Y~m~dT~H~M~S~z")))))
+
+(define (event-overlaps? event begin end)
+ "Returns if the event overlaps the timespan.
+Event must have the DTSTART and DTEND attribute set."
+ (timespan-overlaps? (attr event 'DTSTART)
+ (attr event 'DTEND)
+ begin end))
+
+(define (event-in? ev time)
+ "Does event overlap the date that contains time."
+ (let* ((date (time-utc->date time))
+ (start (date->time-utc (drop-time date)))
+ (end (add-duration start (make-duration (* 60 60 24)))))
+ (event-overlaps? ev start end)))