diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-17 01:11:51 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-17 01:11:51 +0200 |
commit | 7921f776ae41d149e2a031a0d932e6fdd4ce0c6e (patch) | |
tree | 2f5622be6dd1bbdab828c91818a19645a594a3ce /module/vcomponent/duration.scm | |
parent | Fix parse error on duration. (diff) | |
download | calp-7921f776ae41d149e2a031a0d932e6fdd4ce0c6e.tar.gz calp-7921f776ae41d149e2a031a0d932e6fdd4ce0c6e.tar.xz |
Add duration output.
Diffstat (limited to 'module/vcomponent/duration.scm')
-rw-r--r-- | module/vcomponent/duration.scm | 22 |
1 files changed, 22 insertions, 0 deletions
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 |