guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Ludovic Courtès
Date: Wed, 7 Nov 2018 09:28:24 -0500 (EST)

branch: master
commit a1d353b1527fd1a2bfa2a1cbb2f0ff5c79d6e973
Author: Ludovic Courtès <address@hidden>
Date:   Wed Nov 7 14:38:06 2018 +0100

    templates: Display dates in a concise way.
    
    * src/cuirass/templates.scm (time->string): New procedure.
    (build-eval-table): Use it instead of 'strftime'.
---
 src/cuirass/templates.scm | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
index dde0145..1c089a4 100644
--- a/src/cuirass/templates.scm
+++ b/src/cuirass/templates.scm
@@ -21,6 +21,7 @@
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-19)
   #:use-module (srfi srfi-26)
   #:use-module ((cuirass database) #:select (build-status))
   #:export (html-page
@@ -183,6 +184,37 @@
                 (format #f "?border-high=~d" page-id-min))
             (format #f "?border-low=~d" (1- id-min)))))))
 
+(define (time->string time)
+  "Return a string representing TIME in a concise, human-readable way."
+  (define now*
+    (current-time time-utc))
+
+  (define now
+    (time-second now*))
+
+  (define elapsed
+    (- now time))
+
+  (cond ((< elapsed 120)
+         "seconds ago")
+        ((< elapsed 7200)
+         (let ((minutes (inexact->exact
+                         (round (/ elapsed 60)))))
+           (format #f "~a minutes ago" minutes)))
+        ((< elapsed (* 48 3600))
+         (let ((hours (inexact->exact
+                       (round (/ elapsed 3600)))))
+           (format #f "~a hours ago" hours)))
+        (else
+         (let* ((time    (make-time time-utc 0 time))
+                (date    (time-utc->date time))
+                (year    (date-year date))
+                (current (date-year (time-utc->date now*)))
+                (format  (if (= year )
+                             "~e ~b ~H:~M ~z"
+                             "~e ~b ~Y ~H:~M ~z")))
+           (date->string date format)))))
+
 (define (build-eval-table eval-id builds build-min build-max status)
   "Return HTML for the BUILDS table evaluation with given STATUS.  BUILD-MIN
 and BUILD-MAX are global minimal and maximal (stoptime, rowid) pairs."
@@ -233,7 +265,7 @@ and BUILD-MAX are global minimal and maximal (stoptime, 
rowid) pairs."
       (td ,(assq-ref build #:jobset))
       (td ,(if (or (= (build-status succeeded) status)
                    (= (build-status failed) status))
-               (strftime "%c" (localtime (assq-ref build #:stoptime)))
+               (time->string (assq-ref build #:stoptime))
                "—"))
       (td ,(assq-ref build #:job))
       (td ,(assq-ref build #:nixname))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]