download: Only show hours in the elapsed time if necessary.

* guix/build/download.scm
  (seconds->string): Conditionally include hours in timestamp.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
master
Steve Sprang 2015-09-16 20:43:58 -07:00 committed by Ludovic Courtès
parent be3feafedf
commit 47770296d2
1 changed files with 6 additions and 5 deletions

View File

@ -63,16 +63,17 @@ object, as an inexact number."
(/ (time-nanosecond duration) 1e9))) (/ (time-nanosecond duration) 1e9)))
(define (seconds->string duration) (define (seconds->string duration)
"Given DURATION in seconds, return a string representing it in 'hh:mm:ss' "Given DURATION in seconds, return a string representing it in 'mm:ss' or
format." 'hh:mm:ss' format, as needed."
(if (not (number? duration)) (if (not (number? duration))
"00:00:00" "00:00"
(let* ((total-seconds (nearest-exact-integer duration)) (let* ((total-seconds (nearest-exact-integer duration))
(extra-seconds (modulo total-seconds 3600)) (extra-seconds (modulo total-seconds 3600))
(hours (quotient total-seconds 3600)) (num-hours (quotient total-seconds 3600))
(hours (and (positive? num-hours) num-hours))
(mins (quotient extra-seconds 60)) (mins (quotient extra-seconds 60))
(secs (modulo extra-seconds 60))) (secs (modulo extra-seconds 60)))
(format #f "~2,'0d:~2,'0d:~2,'0d" hours mins secs)))) (format #f "~@[~2,'0d:~]~2,'0d:~2,'0d" hours mins secs))))
(define (byte-count->string size) (define (byte-count->string size)
"Given SIZE in bytes, return a string representing it in a human-readable "Given SIZE in bytes, return a string representing it in a human-readable