From 7921f776ae41d149e2a031a0d932e6fdd4ce0c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 17 Jul 2020 01:11:51 +0200 Subject: Add duration output. --- module/vcomponent/duration.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'module/vcomponent/duration.scm') diff --git a/module/vcomponent/duration.scm b/module/vcomponent/duration.scm index 061cc50a..f8ef1d70 100644 --- a/module/vcomponent/duration.scm +++ b/module/vcomponent/duration.scm @@ -23,6 +23,28 @@ (error "Can't give week together with day or time")) (make-duration sign week day time)) + +(define-public (format-duration duration) + (with-output-to-string + (lambda () + (unless (eq? '+ (duration-sign duration)) + (display (duration-sign duration))) + (display "P") + (aif (duration-week duration) + (format #t "~aW" it) + (begin + (awhen (duration-day duration) (format #t "~aD" it)) + (awhen (duration-time duration) + (display "T") + ;; if any non-zero, + (unless (= 0 (hour it) (minute it) (second it)) + (format #t "~aH" (hour it)) + (unless (= 0 (minute it) (second it)) + (format #t "~aM" (minute it)) + (unless (= 0 (second it)) + (format #t "~aS" (second it))))))))))) + + (define-peg-pattern number all (+ (range #\0 #\9))) (define-peg-pattern time-pattern body -- cgit v1.2.3