From 2e96f3a890bcc73457c6a41bf6ee212f8f725854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 4 Jul 2020 17:34:26 +0200 Subject: Clean up datetime parsing. --- module/datetime.scm | 275 ++++++++++++++++++++++++++++++---------------------- module/util.scm | 5 + 2 files changed, 165 insertions(+), 115 deletions(-) diff --git a/module/datetime.scm b/module/datetime.scm index eff3fdba..126695d1 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -44,22 +44,17 @@ date? (year year) (month month) (day day)) -;;; NOTE all these printers would benefit from using datetime->string, -;;; that however is currently in the (datetime util) module, which leads -;;; to a dependency cycle. +(define*-public (date key: (year 0) (month 0) (day 0)) + (make-date year month day)) (set-record-type-printer! (lambda (r p) - (if (or (not (integer? (year r))) - (not (integer? (month r))) - (not (integer? (day r)))) - (format p "BAD~s-~s-~s" (year r) (month r) (day r)) - (format p "#~4'0d-~2'0d-~2'0d" - (year r) (month r) (day r))))) + (catch 'misc-error + (lambda () (display (date->string r "#~Y-~m-~d") p)) + (lambda (err _ fmt args . rest) + (format p "BAD~s-~s-~s" (year r) (month r) (day r)))))) -(define*-public (date key: (year 0) (month 0) (day 0)) - (make-date year month day)) ;;; TIME @@ -68,19 +63,18 @@ time? (hour hour) (minute minute) (second second)) +(define*-public (time key: (hour 0) (minute 0) (second 0)) + (make-time hour minute second)) + (set-record-type-printer!