From 001dfb71c20f50ca4fc0e9d303749fe7bd38664b Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 16 Jul 2023 22:29:18 +0100 Subject: [PATCH] Show elapsed time as D:HH:MM:SS after 1 day, to match the ETA format --- doc/NEWS.md | 1 + doc/TODO.md | 1 - src/pv/display.c | 20 ++++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/NEWS.md b/doc/NEWS.md index 8c76daf..9a1d316 100644 --- a/doc/NEWS.md +++ b/doc/NEWS.md @@ -4,6 +4,7 @@ UNRELEASED * fix: workaround for OS X 11 behaviour in configure script regarding stat64 at compile time (pull request [#57](https://github.com/a-j-wood/pv/pull/57) supplied by [Dave Beckett](https://github.com/dajobe)) * fix: add burst rate limit to transfer, so rate limits are not broken by bursty traffic (pull request [#62](https://github.com/a-j-wood/pv/pull/62) supplied by [Volodymyr Bychkovyak](https://github.com/vbychkoviak)) * fix: corrected "`--force`" option so it will still output progress when not in the same process group as the owner of the terminal - corrects [GH#23 "No output with "`-f`" when run in background after 1.6.6"](https://github.com/a-j-wood/pv/issues/23) and helps to correct [GH#31 "No output written from inside zsh <() construct"](https://github.com/a-j-wood/pv/issues/31) + * fix: corrected elapsed time display to show as D:HH:MM:SS after 1 day, like the ETA does - corrects [GH#16 "Show days in same format in ETA as in elapsed time"](https://github.com/a-j-wood/pv/issues/16) * feature: the "`--size`" option now accepts "`@filename`" to use the size of another file (pull request [#57](https://github.com/a-j-wood/pv/pull/57) supplied by [Dave Beckett](https://github.com/dajobe)) * feature: the "`--watchfd`" option is now available on OS X (pull request [#60](https://github.com/a-j-wood/pv/pull/60) supplied by [christoph-zededa](https://github.com/christoph-zededa)) * feature: new "`--average-rate-window`" option, to set the window over which the average rate is calculated, also used for ETA (modified from pull request [#65](https://github.com/a-j-wood/pv/pull/65) supplied by [lemonsqueeze](https://github.com/lemonsqueeze)) diff --git a/doc/TODO.md b/doc/TODO.md index 746f78d..d4975c5 100644 --- a/doc/TODO.md +++ b/doc/TODO.md @@ -5,7 +5,6 @@ Bugs * ([GH#5](https://github.com/a-j-wood/pv/issues/5)) Transfer IPC leadership on exit of leader * ([GH#13](https://github.com/a-j-wood/pv/issues/13)) Use `clock_gettime()` in ETA calculation to cope with machine suspend/resume (Mateju Miroslav) - * ([GH#16](https://github.com/a-j-wood/pv/issues/16)) Show days in same format in ETA as in elapsed time * ([GH#18](https://github.com/a-j-wood/pv/issues/18)) No output in Cygwin from 1.6.19 onwards (Jacek M. Holeczek) * ([GH#20](https://github.com/a-j-wood/pv/issues/20)) Terminal state is not restored correctly in all cases (VA) * ([GH#24](https://github.com/a-j-wood/pv/issues/24)) Race condition with multiple "`pv -c`" leaves terminal state inconsistent (Lars Ellenberg, Viktor Ashirov) diff --git a/src/pv/display.c b/src/pv/display.c index dbd4176..af42ebd 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -702,10 +702,22 @@ static char *pv__format(pvstate_t state, if (elapsed_sec > (long double) 360000000.0L) elapsed_sec = (long double) 360000000.0L; - sprintf(state->str_timer, "%ld:%02ld:%02ld", - ((long) elapsed_sec) / 3600, - (((long) elapsed_sec) / 60) % 60, - ((long) elapsed_sec) % 60); + /* + * If the elapsed time is more than a day, include a day count as + * well as hours, minutes, and seconds. + */ + if (elapsed_sec > (long double) 86400.0L) { + sprintf(state->str_timer, "%ld:%02ld:%02ld:%02ld", + ((long) elapsed_sec) / 86400, + (((long) elapsed_sec) / 3600) % 24, + (((long) elapsed_sec) / 60) % 60, + ((long) elapsed_sec) % 60); + } else { + sprintf(state->str_timer, "%ld:%02ld:%02ld", + ((long) elapsed_sec) / 3600, + (((long) elapsed_sec) / 60) % 60, + ((long) elapsed_sec) % 60); + } } /* Rate - set up the display string. */