From 71946b84b8a9ffba3a9fa627f34e5dbabec50b4b Mon Sep 17 00:00:00 2001 From: sterni Date: Tue, 19 Jan 2021 14:43:40 +0100 Subject: 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 Reviewed-by: glittershark --- lisp/klatre/klatre.lisp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lisp/klatre') diff --git a/lisp/klatre/klatre.lisp b/lisp/klatre/klatre.lisp index 1c8d4c4d2e..e10ddeea4e 100644 --- a/lisp/klatre/klatre.lisp +++ b/lisp/klatre/klatre.lisp @@ -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." -- cgit 1.4.1