mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix: remove dead conditional branches in duration reset handlers
_handle_hour_reset, _handle_minute_reset and _handle_second_reset each branched on whether the sub-unit fields were exactly zero, but both branches computed an identical expression. The conditions suggested that the exact-boundary case was handled specially when it was not, which is misleading for anyone maintaining budget reset logic. Collapse each branch to the single expression and drop the locals that become unused as a result. No behaviour change: verified by differential testing across 1,733,472 combinations of duration, timezone, reset_time_of_day and timestamp - including exact unit boundaries, invalid durations, leap day and year end - with zero mismatches.
This commit is contained in:
parent
dd01abc439
commit
7dbebaa183
1 changed files with 7 additions and 26 deletions
|
|
@ -260,15 +260,9 @@ def _handle_hour_reset(current_time: datetime, base_midnight: datetime, value: i
|
|||
return current_time
|
||||
|
||||
current_hour: Final = current_time.hour
|
||||
current_minute: Final = current_time.minute
|
||||
current_second: Final = current_time.second
|
||||
current_microsecond: Final = current_time.microsecond
|
||||
|
||||
# Calculate next hour aligned with the value
|
||||
if current_minute == 0 and current_second == 0 and current_microsecond == 0:
|
||||
next_hour = current_hour + value - (current_hour % value) if current_hour % value != 0 else current_hour + value
|
||||
else:
|
||||
next_hour = current_hour + value - (current_hour % value) if current_hour % value != 0 else current_hour + value
|
||||
next_hour = current_hour + value - (current_hour % value) if current_hour % value != 0 else current_hour + value
|
||||
|
||||
# Handle overnight case
|
||||
if next_hour >= 24:
|
||||
|
|
@ -287,18 +281,11 @@ def _handle_minute_reset(current_time: datetime, base_midnight: datetime, value:
|
|||
|
||||
current_hour: Final = current_time.hour
|
||||
current_minute: Final = current_time.minute
|
||||
current_second: Final = current_time.second
|
||||
current_microsecond: Final = current_time.microsecond
|
||||
|
||||
# Calculate next minute aligned with the value
|
||||
if current_second == 0 and current_microsecond == 0:
|
||||
next_minute = (
|
||||
current_minute + value - (current_minute % value) if current_minute % value != 0 else current_minute + value
|
||||
)
|
||||
else:
|
||||
next_minute = (
|
||||
current_minute + value - (current_minute % value) if current_minute % value != 0 else current_minute + value
|
||||
)
|
||||
next_minute = (
|
||||
current_minute + value - (current_minute % value) if current_minute % value != 0 else current_minute + value
|
||||
)
|
||||
|
||||
# Handle hour rollover
|
||||
next_hour = current_hour + (next_minute // 60)
|
||||
|
|
@ -322,17 +309,11 @@ def _handle_second_reset(current_time: datetime, base_midnight: datetime, value:
|
|||
current_hour: Final = current_time.hour
|
||||
current_minute: Final = current_time.minute
|
||||
current_second: Final = current_time.second
|
||||
current_microsecond: Final = current_time.microsecond
|
||||
|
||||
# Calculate next second aligned with the value
|
||||
if current_microsecond == 0:
|
||||
next_second = (
|
||||
current_second + value - (current_second % value) if current_second % value != 0 else current_second + value
|
||||
)
|
||||
else:
|
||||
next_second = (
|
||||
current_second + value - (current_second % value) if current_second % value != 0 else current_second + value
|
||||
)
|
||||
next_second = (
|
||||
current_second + value - (current_second % value) if current_second % value != 0 else current_second + value
|
||||
)
|
||||
|
||||
# Handle minute rollover
|
||||
additional_minutes: Final = next_second // 60
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue