feat(klatre): support offsets in format-dottime

Instead of bothering with local-time's feature rich timezone support we
just pass the offset as an integer and render it ourselves.

Change-Id: I1df2d02153e3ef21ae3b2871ad6ef57d0f6eff86
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2423
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
sterni 2021-01-19 14:43:40 +01:00
parent cf4357d9b7
commit 71946b84b8

View file

@ -76,18 +76,23 @@ separated by SEP."
(defparameter dottime-format (defparameter dottime-format
'((:year 4) #\- (:month 2) #\- (:day 2) '((:year 4) #\- (:month 2) #\- (:day 2)
#\T #\T
(:hour 2) #\· (:min 2) "+00") ; TODO(grfn): Allow passing offset (:hour 2) #\· (:min 2))
"`:LOCAL-TIME' format specifier for dottime") "`:LOCAL-TIME' format specifier for dottime")
(defun format-dottime (timestamp) (defun format-dottime (timestamp &optional (offset 0))
"Return TIMESTAMP formatted as dottime, using a +00 offset" "Return TIMESTAMP formatted as dottime, with a specified offset or +00"
(check-type timestamp local-time:timestamp) (check-type timestamp local-time:timestamp)
(concatenate 'string
(local-time:format-timestring nil timestamp (local-time:format-timestring nil timestamp
:format dottime-format :format dottime-format
:timezone local-time:+utc-zone+)) :timezone local-time:+utc-zone+)
; render sign manually since format prints it after padding
(if (>= offset 0) "+" "-")
(format nil "~2,'0D" (abs offset))))
(comment (comment
(format-dottime (local-time:now))) (format-dottime (local-time:now))
(format-dottime (local-time:now) 2))
(defun try-parse-integer (str) (defun try-parse-integer (str)
"Attempt to parse STR as an integer, returning nil if it is invalid." "Attempt to parse STR as an integer, returning nil if it is invalid."