[PATCH] progress: handle days, weeks and years

timeless timeless at gmail.com
Sun Jan 2 10:58:05 CST 2011


# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1293987119 -7200
# Node ID 840b6b8d097696bd21dee3d79824b7706990a7f9
# Parent  1f4721de2ca9744b3488bf050a11ed23e89889d6
progress: handle days, weeks and years

using hg clone svn://anonsvn.kde.org/home/kde/trunk kde ... with progress
yields 3008/1210830 1314h56m, which is unusable.

Add code to switch to days at 30 hours, to weeks at 15 days, and to years
at 55 weeks. A day has 24 hours, a week has 7 days, and a year has 52 weeks.
Months are intentionally omitted because they do not have a fixed length. The
Use of 52 weeks is a known and understandable estimate for a year.

It might make sense to spell our year to alert people when progress is
impractical, but...

diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -69,8 +69,29 @@ def fmtremaining(seconds):
     minutes += 1
     hours = minutes // 60
     minutes -= hours * 60
-    # i18n: format X hours and YY minutes as "XhYYm"
-    return _("%dh%02dm") % (hours, minutes)
+    if hours < 30:
+        # i18n: format X hours and YY minutes as "XhYYm"
+        return _("%dh%02dm") % (hours, minutes)
+    # we're going to ignore minutes in this case
+    hours += 1
+    days = hours // 24
+    hours -= days * 24
+    if days < 15:
+        # i18n: format X days and YY hours as "XdYYh"
+        return _("%dd%02dh") % (days, hours)
+    # we're going to ignore hours in this case
+    days += 1
+    weeks = days // 7
+    days -= weeks * 7
+    if weeks < 55:
+        # i18n: format X weeks and YY days as "XwYYd"
+        return _("%dw%02dd") % (weeks, days)
+    # we're going to ignore days and treat a year as 52 weeks
+    weeks += 1
+    years = weeks // 52
+    weeks -= years * 52
+    # i18n: format X years and YY weeks as "XyYYw"
+    return _("%dy%02dw") % (years, weeks)
 
 class progbar(object):
     def __init__(self, ui):
diff --git a/tests/test-progress.t b/tests/test-progress.t
--- a/tests/test-progress.t
+++ b/tests/test-progress.t
@@ -141,6 +141,23 @@ test delay time estimates
   loop [==============================>           ] 3/4 2h47m
                                                               \r (esc)
 
+  $ MOCKTIME=1000000 hg -y loop 4 2>&1 | python $TESTDIR/filtercr.py
+  
+  loop [                                                ] 0/4
+  loop [=========>                                ] 1/4 5w00d
+  loop [====================>                     ] 2/4 3w03d
+  loop [=============================>           ] 3/4 11d14h
+                                                              \r (esc)
+
+
+  $ MOCKTIME=14000000 hg -y loop 4 2>&1 | python $TESTDIR/filtercr.py
+  
+  loop [                                                ] 0/4
+  loop [=========>                                ] 1/4 1y18w
+  loop [===================>                     ] 2/4 46w03d
+  loop [=============================>           ] 3/4 23w02d
+                                                              \r (esc)
+
 Time estimates should not fail when there's no end point:
   $ hg -y loop -- -4 2>&1 | python $TESTDIR/filtercr.py
   


More information about the Mercurial-devel mailing list