+
+/* Provide a short human-readable rendition of the ETA. This is like
+ secs_to_human_time in main.c, except the output doesn't include
+ fractions (which would look silly in by nature imprecise ETA) and
+ takes less room. If the time is measured in hours, hours and
+ minutes (but not seconds) are shown; if measured in days, then days
+ and hours are shown. This ensures brevity while still displaying
+ as much as possible.
+
+ If SEP is false, the separator between minutes and seconds (and
+ hours and minutes, etc.) is not included, shortening the display by
+ one additional character. This is used for dot progress.
+
+ The display never occupies more than 7 characters of screen
+ space. */
+
+static const char *
+eta_to_human_short (int secs)
+{
+ static char buf[10]; /* 8 should be enough, but just in case */
+ static int last = -1;
+
+ /* Trivial optimization. create_image can call us every 200 msecs
+ (see bar_update) for fast downloads, but ETA will only change
+ once per 900 msecs. */
+ if (secs == last)
+ return buf;
+ last = secs;
+
+ if (secs < 100)
+ sprintf (buf, "%ds", secs);
+ else if (secs < 100 * 60)
+ sprintf (buf, "%dm %ds", secs / 60, secs % 60);
+ else if (secs < 100 * 3600)
+ sprintf (buf, "%dh %dm", secs / 3600, (secs / 60) % 60);
+ else if (secs < 100 * 86400)
+ sprintf (buf, "%dd %dh", secs / 86400, (secs / 3600) % 60);
+ else
+ /* even (2^31-1)/86400 doesn't overflow BUF. */
+ sprintf (buf, "%dd", secs / 86400);
+
+ return buf;
+}