diff --git a/src/humanize/time.py b/src/humanize/time.py index 7c4a28eb..d1c2afe5 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -608,7 +608,7 @@ def precisedelta( secs, 60, MINUTES, min_unit, suppress_set, format ) - usecs = secs * 1e6 + usecs + usecs = secs * 1_000_000 + usecs secs, usecs = _quotient_and_remainder( usecs, 1e6, SECONDS, min_unit, suppress_set, format ) diff --git a/tests/test_time.py b/tests/test_time.py index 887a3fc5..344689d5 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -838,6 +838,25 @@ def test_precisedelta_suppress_units( ) +@pytest.mark.parametrize("microseconds", [2**53 - 1, 2**53 + 1, 2**53 + 3]) +@pytest.mark.parametrize("sign", [1, -1]) +def test_precisedelta_large_microsecond_count(microseconds: int, sign: int) -> None: + value = dt.timedelta(microseconds=sign * microseconds) + suppress = [ + "years", + "months", + "days", + "hours", + "minutes", + "seconds", + "milliseconds", + ] + assert ( + humanize.precisedelta(value, minimum_unit="microseconds", suppress=suppress) + == f"{microseconds} microseconds" + ) + + def test_precisedelta_bogus_call() -> None: assert humanize.precisedelta(None) == "None"