about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-22T02·07-0400
committerglittershark <grfn@gws.fyi>2020-07-23T00·08+0000
commitf591c32dfb2a9f0246c8d6501c1efab4c80da52f (patch)
treeb677488b378902a6721c570d4be54a49be3326cf
parentd60c639162e8390397b6808f78ac4e2def9324cb (diff)
feat(klatre): add dottime-format function r/1422
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 <mail@tazj.in>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
-rw-r--r--lisp/klatre/default.nix4
-rw-r--r--lisp/klatre/klatre.lisp20
-rw-r--r--lisp/klatre/package.lisp5
3 files changed, 28 insertions, 1 deletions
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))