From 982d6c8cd5ba6ade04683e5699fc9fc170e4c109 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 1 Apr 2023 13:05:40 +0200 Subject: fix round_to_multiple for second-level accuracy It was ovious that this is broken when you try to round "0s" to second-level granularity, and you end up with "1s". The problem comes from the fact that we use the integer divison when checking whether we should round up or down, but then also use strict inequality. To fix this, we now also round down if the second_offset is equal to the halfway point (which in the case of second-level granularity is 0). --- tests/unit/test_util.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 949acb5..0ac5c33 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -29,6 +29,11 @@ def test_fix_iso_timestamp(timestamp, fixed): @pytest.mark.parametrize('delta, multiple, expected', [ + ( + timedelta(seconds=0), + timedelta(seconds=1), + timedelta(seconds=0), + ), ( timedelta(minutes=42), timedelta(minutes=15), -- cgit v1.2.3