From 921a3a0af99f999eea387988f34a0603ab3173a2 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:03:28 -0700 Subject: [PATCH] Round human duration to nearest significant base --- data/interfaces/default/js/script.js | 3 ++- plexpy/helpers.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/interfaces/default/js/script.js b/data/interfaces/default/js/script.js index 2df5daeb..c04ce6ef 100644 --- a/data/interfaces/default/js/script.js +++ b/data/interfaces/default/js/script.js @@ -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']); diff --git a/plexpy/helpers.py b/plexpy/helpers.py index 014f1359..dfc82d25 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -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'])