From ae47899079a448b2d71101d4b21c8e9409d82e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 23 Mar 2020 00:34:28 +0100 Subject: Remove deprecated get-time. --- module/datetime/util.scm | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'module/datetime') diff --git a/module/datetime/util.scm b/module/datetime/util.scm index ff75e86d..d5558aa2 100644 --- a/module/datetime/util.scm +++ b/module/datetime/util.scm @@ -150,7 +150,29 @@ #f (string->list fmt))))) -(define*-public (time->string time optional: (fmt "~H:~M:~S") key: allow-unknown?) +;; (define*-public (time->string time optional: (fmt "~H:~M:~S") key: allow-unknown?) +;; (with-output-to-string +;; (lambda () +;; (fold (lambda (token state) +;; (case state +;; ((#\~) +;; (case token +;; ((#\~) (display "~")) +;; ((#\H) (format #t "~2'0d" (hour time))) +;; ((#\M) (format #t "~2'0d" (minute time))) +;; ((#\S) (format #t "~2'0d" (second time))) +;; ;; ((#\z) (when (utc? time) (display "Z"))) +;; (else (unless allow-unknown? +;; (error 'time->string "Invalid format token ~a" token)))) +;; #f) +;; (else (unless (char=? #\~ token) (display token)) token))) +;; #f +;; (string->list fmt))))) + +(define*-public (datetime->string datetime optional: (fmt "~Y-~m-~dT~H:~M:~S") key: allow-unknown?) + (define dt (get-datetime datetime)) + (define date (get-date dt)) + (define time ((@ (datetime) get-time%) dt)) (with-output-to-string (lambda () (fold (lambda (token state) @@ -161,9 +183,21 @@ ((#\H) (format #t "~2'0d" (hour time))) ((#\M) (format #t "~2'0d" (minute time))) ((#\S) (format #t "~2'0d" (second time))) + ;; TODO ;; ((#\z) (when (utc? time) (display "Z"))) + ((#\Y) (format #t "~4'0d" (year date))) + ((#\m) (format #t "~2'0d" (month date))) + ((#\d) (format #t "~2'0d" (day date))) + ;; Should be same as ~_d + ((#\e) (format #t "~2' d" (day date))) + ((#\1) (format #t "~4'0d-~2'0d-~2'0d" + (year date) (month date) (day date))) + ((#\a) (display (week-day-name (week-day date)))) + ;; abriviated locale month name + ;; TODO locale + ((#\b) (display (month-name (month date)))) (else (unless allow-unknown? - (error 'time->string "Invalid format token ~a" token)))) + (error 'datetime->string "Invalid format token ~a" token)))) #f) (else (unless (char=? #\~ token) (display token)) token))) #f @@ -171,7 +205,6 @@ - ;; @verbatim ;; A B C D E ¬F ;; |s1| : |s2| : |s1| : |s2| : : |s1| -- cgit v1.2.3