From f591c32dfb2a9f0246c8d6501c1efab4c80da52f Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Tue, 21 Jul 2020 22:07:26 -0400 Subject: feat(klatre): add dottime-format function Add a function to klatre format a timestamp using dottime Change-Id: I24d8d91f49f352b606f44834f7229ab55b55afa0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1344 Tested-by: BuildkiteCI Reviewed-by: tazjin Reviewed-by: kanepyork --- lisp/klatre/default.nix | 4 ++++ lisp/klatre/klatre.lisp | 20 ++++++++++++++++++++ lisp/klatre/package.lisp | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/klatre/default.nix b/lisp/klatre/default.nix index 41c3ef8094..2c7bb6490a 100644 --- a/lisp/klatre/default.nix +++ b/lisp/klatre/default.nix @@ -3,6 +3,10 @@ depot.nix.buildLisp.library { name = "klatre"; + deps = with depot.third_party.lisp; [ + local-time + ]; + srcs = [ ./package.lisp ./klatre.lisp diff --git a/lisp/klatre/klatre.lisp b/lisp/klatre/klatre.lisp index afe16a90b8..231e72b64f 100644 --- a/lisp/klatre/klatre.lisp +++ b/lisp/klatre/klatre.lisp @@ -68,3 +68,23 @@ separated by SEP." (vector-push-extend (char sep (the fixnum k)) vs)))) lst) vs)) + +;;; +;;; String handling +;;; + +(defconstant +dottime-format+ + '((:year 4) #\- (:month 2) #\- (:day 2) + #\T + (:hour 2) #\ยท (:min 2) "+00") ; TODO(grfn): Allow passing offset + "`:LOCAL-TIME' format specifier for dottime") + +(defun format-dottime (timestamp) + "Return TIMESTAMP formatted as dottime, using a +00 offset" + (check-type timestamp local-time:timestamp) + (local-time:format-timestring nil timestamp + :format +dottime-format+ + :timezone local-time:+utc-zone+)) + +(comment + (format-dottime (local-time:now))) diff --git a/lisp/klatre/package.lisp b/lisp/klatre/package.lisp index 0cf7336feb..b5f574fa16 100644 --- a/lisp/klatre/package.lisp +++ b/lisp/klatre/package.lisp @@ -6,4 +6,7 @@ #:comment #:posp ;; Sequence functions - #:chunk-list #:mapconcat)) + #:chunk-list #:mapconcat + + ;; String handling + #:+dottime-format+ #:format-dottime)) -- cgit 1.4.1