about summary refs log tree commit diff
path: root/dump
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-03-15 13:15:54 +0300
committerBonfaceKilz2023-04-05 16:17:11 +0300
commit9a8115504747f79254606a6f063d0f46ffbf13a0 (patch)
treef94314b2edf894330432fde3e54a2d742bb698ca /dump
parentaa1ef98b116ba2cf032e7ba5b34a777626a89d43 (diff)
downloadgn-transform-databases-9a8115504747f79254606a6f063d0f46ffbf13a0.tar.gz
Add a method to transform epoch time to a human readable format
* dump/utils.scm: Import srfi-19.  Export time-unix->string.
(time-unix->string): New function.

Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'dump')
-rw-r--r--dump/utils.scm18
1 files changed, 17 insertions, 1 deletions
diff --git a/dump/utils.scm b/dump/utils.scm
index d033f17..8544eec 100644
--- a/dump/utils.scm
+++ b/dump/utils.scm
@@ -1,11 +1,27 @@
 (define-module (dump utils)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-19)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
   #:export (string-blank?
             translate-forms
             collect-forms
-            map-alist))
+            map-alist
+            time-unix->string))
+
+
+(define (time-unix->string seconds . maybe-format)
+  "Given an integer saying the number of seconds since the Unix
+epoch (1970-01-01 00:00:00), SECONDS, format it as a human readable
+date and time-string, possible using the MAYBE-FORMAT."
+  (letrec ([time-unix->time-utc
+            (lambda (seconds)
+              (add-duration
+               (date->time-utc (make-date 0 0 0 0 1 1 1970 0))
+               (make-time time-duration 0 seconds)))])
+    (apply date->string
+           (time-utc->date (time-unix->time-utc seconds))
+           maybe-format)))
 
 (define (string-blank? str)
   "Return non-#f if STR consists only of whitespace characters."