Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/utils/time_rounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def round_time_duration(duration_seconds: int, rounding_minutes: int = 1, roundi
rounded_minutes = math.ceil(duration_minutes / rounding_minutes) * rounding_minutes
elif rounding_method == "down":
rounded_minutes = math.floor(duration_minutes / rounding_minutes) * rounding_minutes
else: # 'nearest'
rounded_minutes = round(duration_minutes / rounding_minutes) * rounding_minutes
else: # 'nearest', halves round up (round() would round them to even)
rounded_minutes = math.floor(duration_minutes / rounding_minutes + 0.5) * rounding_minutes

# Convert back to seconds
return int(rounded_minutes * 60)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_time_rounding_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
pytest.param(3720, 60, "nearest", 3600, id="62m->nearest-60m=60m"),
pytest.param(5400, 60, "nearest", 7200, id="90m->nearest-60m=120m"),
pytest.param(5340, 60, "nearest", 3600, id="89m->nearest-60m=60m"),
pytest.param(900, 30, "nearest", 1800, id="15m->nearest-30m=30m"),
pytest.param(9000, 60, "nearest", 10800, id="150m->nearest-60m=180m"),
],
)
def test_round_time_duration_parametrized(seconds, interval, method, expected):
Expand Down
Loading