aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-04-10 00:49:46 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2019-04-10 00:49:46 +0200
commit76a959bda2ac9acf36c73a55e2993c6403578ec9 (patch)
tree41119523d0721dd2209e729943dbdb8219d9c155
parentAdd some stuff to guile_type_helpers. (diff)
downloadcalp-76a959bda2ac9acf36c73a55e2993c6403578ec9.tar.gz
calp-76a959bda2ac9acf36c73a55e2993c6403578ec9.tar.xz
Add {format,print}-recur-rule.
-rw-r--r--module/vcalendar/recurrence/internal.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/module/vcalendar/recurrence/internal.scm b/module/vcalendar/recurrence/internal.scm
index 0f03abc0..caa6ccca 100644
--- a/module/vcalendar/recurrence/internal.scm
+++ b/module/vcalendar/recurrence/internal.scm
@@ -14,6 +14,31 @@
(define (make-recur-rule interval wkst)
((record-constructor <recur-rule> '(interval wkst)) interval wkst))
+;; TODO make this part of define-quick-record.
+;; Only "hard" part would be to provide type hints for fields for
+;; string conversions.
+(define (format-recur-rule r)
+ (define (a f)
+ ((record-accessor <recur-rule> f) r))
+ (with-output-to-string
+ (lambda ()
+ (format #t "#<recur-rule>~%")
+ (for-each
+ (lambda (field)
+ (when (a field)
+ (format #t " ~8@a: ~a~%"
+ field
+ ((case field
+ ((until) (@ (srfi srfi-19 util) time->string))
+ (else identity))
+ (a field)))))
+ (record-type-fields <recur-rule>)))))
+
+(define* (print-recur-rule r #:optional (port (current-output-port)))
+ (display (format-recur-rule r) port))
+
+(export format-recur-rule print-recur-rule)
+
(define weekdays
'(SU MO TU WE TH FR SA))