aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/common.py b/common.py
index 1635195..f0ddaa4 100644
--- a/common.py
+++ b/common.py
@@ -22,7 +22,7 @@ from fnmatch import fnmatchcase
from pathlib import Path, PosixPath
from urllib.parse import urlparse, urlunparse
from stat import S_ISDIR
-from math import modf
+from math import floor
from xdg.BaseDirectory import xdg_config_home
import logging
import yaml
@@ -182,11 +182,13 @@ def format_bytes(n):
else:
return f'{n/1073741824:.2f}\u202FGiB'
-def format_time(s):
- fs, s = modf(s)
- m, s = divmod(int(s), 60)
+def format_time(ts : float, precision : int = 3) -> str:
+ w = 2 if precision == 0 else precision + 3
+ ts = round(ts, precision)
+ m = floor(ts/60.)
+ s = ts - 60. * m
h, m = divmod(m, 60)
- return f'{h:02d}:{m:02d}:{s + fs:06.3f}'
+ return f'{h:02d}:{m:02d}:{s:0{w}.{precision}f}'
# Return a boolean indicating whether the installer GDAL version is
# greater than or equal to the provider (maj, min, rev) triplet.