aboutsummaryrefslogtreecommitdiffstats
path: root/common.py
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-04-17 11:42:39 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-04-17 11:42:39 +0200
commit4bcf4d8a3229c89813cbf3c05f4ef14cc80202d9 (patch)
tree96045680f7207aec687cc94e6fdfcfc1a08a3e4f /common.py
parente6a0d814659f418287eab6142af726eab929ac87 (diff)
Fix common.format_time().
And add an optional precision argument
Diffstat (limited to 'common.py')
-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.