Round human duration to nearest significant base

This commit is contained in:
JonnyWong16 2024-09-22 18:03:28 -07:00
parent 3bb53f480e
commit 921a3a0af9
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 4 additions and 2 deletions

View file

@ -360,7 +360,8 @@ function humanDuration(ms, sig='dhm', units='ms', return_seconds=300000) {
sig = 'dhms'
}
ms = ms * factors[units];
r = factors[sig.slice(-1)];
ms = Math.round(ms * factors[units] / r) * r;
h = ms % factors['d'];
d = Math.trunc(ms / factors['d']);

View file

@ -272,7 +272,8 @@ def human_duration(ms, sig='dhm', units='ms', return_seconds=300000):
if return_seconds and ms < return_seconds:
sig = 'dhms'
ms = ms * factors[units]
r = factors[sig[-1]]
ms = round(ms * factors[units] / r) * r
d, h = divmod(ms, factors['d'])
h, m = divmod(h, factors['h'])