Browse Source

mmgen.util2: new `format_elapsed_days_hr()` function

The MMGen Project 1 year ago
parent
commit
3febba1711
1 changed files with 7 additions and 0 deletions
  1. 7 0
      mmgen/util2.py

+ 7 - 0
mmgen/util2.py

@@ -118,6 +118,13 @@ def parse_bytespec(nbytes):
 
 	die(1,f'{nbytes!r}: invalid byte specifier')
 
+def format_elapsed_days_hr(t,now=None,cached={}):
+	e = int((now or time.time()) - t)
+	if not e in cached:
+		days = abs(e) // 86400
+		cached[e] = f'{days} day{suf(days)} ' + ('ago' if e > 0 else 'in the future')
+	return cached[e]
+
 def format_elapsed_hr(t,now=None,cached={}):
 	e = int((now or time.time()) - t)
 	if not e in cached: