aboutsummaryrefslogtreecommitdiff
path: root/module/datetime
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-03-19 16:30:46 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2020-03-19 16:30:46 +0100
commitdfa311c997a67fbf19d51b3eb2204d76e45d222f (patch)
treea56c3208ed7d53a9a424b7031ee5c21cf41ab3f3 /module/datetime
parentChange calendar table to be css grid. (diff)
downloadcalp-dfa311c997a67fbf19d51b3eb2204d76e45d222f.tar.gz
calp-dfa311c997a67fbf19d51b3eb2204d76e45d222f.tar.xz
Add ~e and ~b to date->string.
Diffstat (limited to 'module/datetime')
-rw-r--r--module/datetime/util.scm22
1 files changed, 22 insertions, 0 deletions
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)