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:
parent
cf4357d9b7
commit
71946b84b8
1 changed files with 12 additions and 7 deletions
|
@ -76,18 +76,23 @@ separated by SEP."
|
|||
(defparameter dottime-format
|
||||
'((:year 4) #\- (:month 2) #\- (:day 2)
|
||||
#\T
|
||||
(:hour 2) #\· (:min 2) "+00") ; TODO(grfn): Allow passing offset
|
||||
(:hour 2) #\· (:min 2))
|
||||
"`:LOCAL-TIME' format specifier for dottime")
|
||||
|
||||
(defun format-dottime (timestamp)
|
||||
"Return TIMESTAMP formatted as dottime, using a +00 offset"
|
||||
(defun format-dottime (timestamp &optional (offset 0))
|
||||
"Return TIMESTAMP formatted as dottime, with a specified offset or +00"
|
||||
(check-type timestamp local-time:timestamp)
|
||||
(local-time:format-timestring nil timestamp
|
||||
:format dottime-format
|
||||
:timezone local-time:+utc-zone+))
|
||||
(concatenate 'string
|
||||
(local-time:format-timestring nil timestamp
|
||||
:format dottime-format
|
||||
:timezone local-time:+utc-zone+)
|
||||
; render sign manually since format prints it after padding
|
||||
(if (>= offset 0) "+" "-")
|
||||
(format nil "~2,'0D" (abs offset))))
|
||||
|
||||
(comment
|
||||
(format-dottime (local-time:now)))
|
||||
(format-dottime (local-time:now))
|
||||
(format-dottime (local-time:now) 2))
|
||||
|
||||
(defun try-parse-integer (str)
|
||||
"Attempt to parse STR as an integer, returning nil if it is invalid."
|
||||
|
|
Loading…
Reference in a new issue