Estimated time to completion display shortened from eg "1h1m1s" to "1h1m"

Because seconds accuracy over such a time is unlikely to be accurate.
Also, it was possible to get a ridiculous "1y1d1h1m1s" if stalled or
very slow.
This commit is contained in:
Joey Hess 2019-01-20 20:00:05 -04:00
parent 68198e803e
commit e38b654096
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 8 additions and 5 deletions

View file

@ -35,6 +35,7 @@ git-annex (7.20181212) UNRELEASED; urgency=medium
is interrupted be cleaned up promptly by subsequent git-annex processes.
* The .git/annex/misctmp directory is no longer used and git-annex will
delete anything lingering in there after it's 1 week old.
* Estimated time to completion display shortened from eg "1h1m1s" to "1h1m".
-- Joey Hess <id@joeyh.name> Tue, 18 Dec 2018 12:24:52 -0400

View file

@ -60,15 +60,17 @@ parseDuration = maybe parsefail (return . Duration) . go 0
fromDuration :: Duration -> String
fromDuration Duration { durationSeconds = d }
| d == 0 = "0s"
| otherwise = concatMap showunit $ go [] units d
| otherwise = concatMap showunit $ take 2 $ go [] units d
where
showunit (u, n)
| n > 0 = show n ++ [u]
| otherwise = ""
showunit (u, n) = show n ++ [u]
go c [] _ = reverse c
go c ((u, n):us) v =
let (q,r) = v `quotRem` n
in go ((u, q):c) us r
in if q > 0
then go ((u, q):c) us r
else if null c
then go c us r
else reverse c
units :: [(Char, Integer)]
units =