From 34bb90db7c3f4aa9a1dc131071646f57d01ad745 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Tue, 13 Jan 2015 18:05:37 -0500 Subject: [PATCH] Add unix-timestamp-to-timestamptz transform --- src/utils/transforms.lisp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index e11710c..c04cfc3 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -227,3 +227,20 @@ (t date-string-or-integer))))))) + +(defun unix-timestamp-to-timestamptz (unixtime-string) + "Takes a unix timestamp (seconds since beginning of 1970) and converts it + into a string of format \"YYYY-MM-DD hh:mm:ssZ\". + + Assumes that the unix timestamp is in UTC time." + (when unixtime-string + (let ((unixtime (ensure-parse-integer unixtime-string)) + ;; Universal time uses a different epoch than unix time + (unix-universal-diff (load-time-value + (encode-universal-time 0 0 0 1 1 1970 0)))) + (multiple-value-bind + (second minute hour date month year) + (decode-universal-time (+ unixtime unix-universal-diff) 0) + (format nil + "~d-~2,'0d-~2,'0d ~2,'0d:~2,'0d:~2,'0dZ" + year month date hour minute second)))))