aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-03-24 22:53:13 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2020-03-24 22:53:13 +0100
commitacb7a2e2071abb8743b04aabf53079ba5733a91c (patch)
treef3fde6342859db2e7efb0f64645c962744936827
parentChange date{,time}-difference to hopefully sensible types. (diff)
downloadcalp-acb7a2e2071abb8743b04aabf53079ba5733a91c.tar.gz
calp-acb7a2e2071abb8743b04aabf53079ba5733a91c.tar.xz
Add datetime->decimal-hour.
-rw-r--r--module/output/html.scm11
1 files changed, 11 insertions, 0 deletions
diff --git a/module/output/html.scm b/module/output/html.scm
index 9f5c7c81..e9b7fd13 100644
--- a/module/output/html.scm
+++ b/module/output/html.scm
@@ -39,6 +39,17 @@
(/ (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 #\- #\_))