From dfa311c997a67fbf19d51b3eb2204d76e45d222f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 19 Mar 2020 16:30:46 +0100 Subject: Add ~e and ~b to date->string. --- module/datetime/util.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'module/datetime') diff --git a/module/datetime/util.scm b/module/datetime/util.scm index 629ed503..268166d1 100644 --- a/module/datetime/util.scm +++ b/module/datetime/util.scm @@ -90,20 +90,42 @@ (string-take str truncate-to) str))) +(define (month-name month) + (case month + [(1) "Jan"] + [(2) "Feb"] + [(3) "Mar"] + [(4) "Apr"] + [(5) "Maj"] + [(6) "Jun"] + [(7) "Jul"] + [(8) "Aug"] + [(9) "Sep"] + [(10) "Okt"] + [(11) "Nov"] + [(12) "Dec"] + [else (error "No month ~a" month)])) + (define*-public (date->string date optional: (fmt "~Y-~m-~d") key: allow-unknown?) (with-output-to-string (lambda () (fold (lambda (token state) (case state + ;; TODO add #\_ to change pad to spaces ((#\~) (case token ((#\~) (display "~")) ((#\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 'date->string "Invalid format token ~a" token)))) #f) -- cgit v1.2.3