From 6546132ed7b3fdc556912eab7fbc709875cb0b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 24 Mar 2020 23:02:24 +0100 Subject: Move some datetime procedures to propper modules. --- module/datetime.scm | 22 ++++++++++++++++++++++ module/output/html.scm | 29 +---------------------------- module/vcomponent/datetime.scm | 10 ++++++++++ 3 files changed, 33 insertions(+), 28 deletions(-) (limited to 'module') 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))))) -- cgit v1.2.3