aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-03-24 23:02:24 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2020-03-24 23:02:24 +0100
commit6546132ed7b3fdc556912eab7fbc709875cb0b73 (patch)
treec960b3bc91415814ea744579addd3b0338ef5682
parentAdd comment about DST and create-top-block. (diff)
downloadcalp-6546132ed7b3fdc556912eab7fbc709875cb0b73.tar.gz
calp-6546132ed7b3fdc556912eab7fbc709875cb0b73.tar.xz
Move some datetime procedures to propper modules.
-rw-r--r--module/datetime.scm22
-rw-r--r--module/output/html.scm29
-rw-r--r--module/vcomponent/datetime.scm10
3 files changed, 33 insertions, 28 deletions
diff --git a/module/datetime.scm b/module/datetime.scm
index 4a53ed95..aebc7433 100644
--- a/module/datetime.scm
+++ b/module/datetime.scm
@@ -648,6 +648,28 @@
+
+;; @example
+;; (time->decimal-hour #10:30:00) ; => 10.5
+;; @end example
+(define-public (time->decimal-hour time)
+ (exact->inexact (+ (hour time)
+ (/ (minute time) 60)
+ (/ (second time) 3600))))
+
+(define-public (datetime->decimal-hour dt)
+ (unless (and (zero? (month (get-date dt)))
+ (zero? (year (get-date dt))))
+ (error "Multi-month intervals not yet supported" dt))
+ ;; TODO
+ ;; (date-difference #2020-12-31 #2020-01-01) ; => 0000-11-30
+ ;; to get number of days in diff-time we need to count number of days
+ ;; in each month from start and forward
+ (+ (time->decimal-hour (get-time% dt))
+ (* (day (get-date dt)) 24)))
+
+
+
;;; Parsers for vcomponent usage
;; substring to number, local here
diff --git a/module/output/html.scm b/module/output/html.scm
index 70c9f17c..cf200ea3 100644
--- a/module/output/html.scm
+++ b/module/output/html.scm
@@ -31,25 +31,6 @@
(datetime->string (as-datetime (attr ev 'DTSTART)) "~Y~m~d~H~M~S")
(html-attr (attr ev 'UID))))
-;; This should only be used on time intervals, never on absolute times.
-;; For that see @var{date->decimal-hour}.
-;; NOTE Above comment probably deprecated
-(define (time->decimal-hour time)
- (exact->inexact (+ (hour time)
- (/ (minute time) 60)
- (/ (second time) 3600))))
-
-(define (datetime->decimal-hour dt)
- (unless (and (zero? (month (get-date dt)))
- (zero? (year (get-date dt))))
- (error "Multi-month intervals not yet supported" dt))
- ;; TODO
- ;; (date-difference #2020-12-31 #2020-01-01) ; => 0000-11-30
- ;; to get number of days in diff-time we need to count number of days
- ;; in each month from start and forward
- (+ (time->decimal-hour ((@ (datetime) get-time%) dt))
- (* (day (get-date dt)) 24)))
-
;; Retuns an HTML-safe version of @var{str}.
(define (html-attr str)
(define cs (char-set-adjoin char-set:letter+digit #\- #\_))
@@ -87,15 +68,7 @@
(cons `(tr ,@row)
(tablify rest width)))))
-;; An event is considered long if it's DTSTARt (and thereby DTEND) lacks a time component,
-;; or if the total length of the event is greater than 24h.
-;; For practical purposes, an event being long means that it shouldn't be rendered as a part
-;; of a regular day.
-(define (long-event? ev)
- (or (date? (attr ev 'DTSTART))
- (datetime<= (datetime date: (date day: 1))
- (datetime-difference (attr ev 'DTEND)
- (attr ev 'DTSTART)))))
+
(define (event-debug-html event)
diff --git a/module/vcomponent/datetime.scm b/module/vcomponent/datetime.scm
index 5df4dfab..b3940644 100644
--- a/module/vcomponent/datetime.scm
+++ b/module/vcomponent/datetime.scm
@@ -93,3 +93,13 @@ Event must have the DTSTART and DTEND attribute set."
;; 22:00 - 03:00
;; 2h för dag 1
;; 3h för dag 2
+
+;; An event is considered long if it's DTSTART (and thereby DTEND) lacks a time component,
+;; or if the total length of the event is greater than 24h.
+;; For practical purposes, an event being long means that it shouldn't be rendered as a part
+;; of a regular day.
+(define-public (long-event? ev)
+ (or (date? (attr ev 'DTSTART))
+ (datetime<= (datetime date: (date day: 1))
+ (datetime-difference (attr ev 'DTEND)
+ (attr ev 'DTSTART)))))