From a1d353b1527fd1a2bfa2a1cbb2f0ff5c79d6e973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 7 Nov 2018 14:38:06 +0100 Subject: 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)) -- cgit v1.2.3