changeset 13236:3f299f5d9a29

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...
author timeless <timeless@gmail.com>
date Sun, 02 Jan 2011 18:51:59 +0200
parents 6bf39d88c857
children c046978cc0a9
files hgext/progress.py tests/test-progress.t
diffstat 2 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/progress.py	Sun Jan 02 19:34:41 2011 +0100
+++ b/hgext/progress.py	Sun Jan 02 18:51:59 2011 +0200
@@ -69,8 +69,29 @@
     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):
--- a/tests/test-progress.t	Sun Jan 02 19:34:41 2011 +0100
+++ b/tests/test-progress.t	Sun Jan 02 18:51:59 2011 +0200
@@ -141,6 +141,23 @@
   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