From a3a1673de90da5e60a45f28614f2c4e8fdc14e93 Mon Sep 17 00:00:00 2001 From: Jeremy Silver Date: Sat, 24 Oct 2026 14:20:24 -0400 Subject: [PATCH] fix: round fractional seconds instead of truncating --- pytimeparse/tests/testtimeparse.py | 4 +++- pytimeparse/timeparse.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pytimeparse/tests/testtimeparse.py b/pytimeparse/tests/testtimeparse.py index d9e15b3..4a05558 100644 --- a/pytimeparse/tests/testtimeparse.py +++ b/pytimeparse/tests/testtimeparse.py @@ -125,7 +125,9 @@ def test_fractional_units_exact_integer_results(self): ("0.41w", 247968), ("4.1 minutes", 246), ("4.1h30s", 14790), - ("1.33333h", 4799), + ("1.33333h", 4800), + ("0.33333d", 28800), + ("0.3333333333333333d", 28800), ] for text, expected in cases: for prefix, sign in [("", 1), ("+", 1), ("-", -1)]: diff --git a/pytimeparse/timeparse.py b/pytimeparse/timeparse.py index 93e8001..d157b8a 100644 --- a/pytimeparse/timeparse.py +++ b/pytimeparse/timeparse.py @@ -191,7 +191,7 @@ def timeparse(sval: str, granularity: str = "seconds") -> Optional[Union[int, fl return sign * ( # sum exactly so that values such as '4.1m' are # not truncated one second short by float error - int( + round( sum( [ MULTIPLIERS[k] * Decimal(v)