unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] download: Only show hours in the elapsed time if necessary.
@ 2015-09-17  3:50 Steve Sprang
  2015-09-17 12:44 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Sprang @ 2015-09-17  3:50 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 112 bytes --]

Drop hours from the elapsed time (unless necessary) since most downloads
will be much faster than that.

-Steve

[-- Attachment #1.2: Type: text/html, Size: 154 bytes --]

[-- Attachment #2: timestamp.patch --]
[-- Type: text/x-patch, Size: 1639 bytes --]

From 5f4cafc1c0b6d261b0f19a77c64e8700784c8d9a Mon Sep 17 00:00:00 2001
From: Steve Sprang <scs@stevesprang.com>
Date: Wed, 16 Sep 2015 20:43:58 -0700
Subject: [PATCH] download: Only show hours in the elapsed time if necessary.

* guix/build/download.scm
  (seconds->string): Conditionally include hours in timestamp.
---
 guix/build/download.scm | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/guix/build/download.scm b/guix/build/download.scm
index 9b72e8f..d362fc1 100644
--- a/guix/build/download.scm
+++ b/guix/build/download.scm
@@ -63,16 +63,17 @@ object, as an inexact number."
      (/ (time-nanosecond duration) 1e9)))
 
 (define (seconds->string duration)
-  "Given DURATION in seconds, return a string representing it in 'hh:mm:ss'
-format."
+  "Given DURATION in seconds, return a string representing it in 'mm:ss' or
+'hh:mm:ss' format, as needed."
   (if (not (number? duration))
-      "00:00:00"
+      "00:00"
       (let* ((total-seconds (nearest-exact-integer duration))
              (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))
              (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)
   "Given SIZE in bytes, return a string representing it in a human-readable
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] download: Only show hours in the elapsed time if necessary.
  2015-09-17  3:50 [PATCH] download: Only show hours in the elapsed time if necessary Steve Sprang
@ 2015-09-17 12:44 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2015-09-17 12:44 UTC (permalink / raw)
  To: Steve Sprang; +Cc: guix-devel

Steve Sprang <steve.sprang@gmail.com> skribis:

> From 5f4cafc1c0b6d261b0f19a77c64e8700784c8d9a Mon Sep 17 00:00:00 2001
> From: Steve Sprang <scs@stevesprang.com>
> Date: Wed, 16 Sep 2015 20:43:58 -0700
> Subject: [PATCH] download: Only show hours in the elapsed time if necessary.
>
> * guix/build/download.scm
>   (seconds->string): Conditionally include hours in timestamp.

Pushed, thanks.

Ludo’.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-17 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-17  3:50 [PATCH] download: Only show hours in the elapsed time if necessary Steve Sprang
2015-09-17 12:44 ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).