From 4bcf4d8a3229c89813cbf3c05f4ef14cc80202d9 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 17 Apr 2025 11:42:39 +0200 Subject: Fix common.format_time(). And add an optional precision argument --- common.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'common.py') 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. -- cgit v1.2.3