added year as an allowable time unit for display
[p2pool.git] / p2pool / util / math.py
index c13494f..04ed3ff 100644 (file)
@@ -82,7 +82,7 @@ def format(x):
     return '%i' % (x,) + s
 
 def format_dt(dt):
-    for value, name in [(60*60*24, 'days'), (60*60, 'hours'), (60, 'minutes'), (1, 'seconds')]:
+    for value, name in [(365.2425*60*60*24, 'years'), (60*60*24, 'days'), (60*60, 'hours'), (60, 'minutes'), (1, 'seconds')]:
         if dt > value:
             break
     return '%.01f %s' % (dt/value, name)
@@ -179,7 +179,7 @@ def natural_to_string(n, alphabet=None):
     if n < 0:
         raise TypeError('n must be a natural')
     if alphabet is None:
-        s = '%x' % (n,)
+        s = ('%x' % (n,)).lstrip('0')
         if len(s) % 2:
             s = '0' + s
         return s.decode('hex')