mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix: add week unit support to get_next_standardized_reset_time
The function handled d/h/m/s/mo units but silently fell through to the default next-midnight branch for the w (week) unit. This was inconsistent: _extract_from_regex already accepted w in its character class, and duration_in_seconds already returned value * 604800 for it. Add the missing elif unit == 'w' branch that delegates to _handle_day_reset with value * 7, which reuses the existing Monday- alignment logic for 1w and the generic N-day-from-midnight path for larger multiples. Add test_week_based_resets covering 1w from a Wednesday (expects next Monday) and 2w from a Monday (expects 14 days forward at midnight). Signed-off-by: FugoP <264910004+AgentGymLeader@users.noreply.github.com>
This commit is contained in:
parent
50522157dc
commit
13278b4a68
2 changed files with 13 additions and 0 deletions
|
|
@ -131,6 +131,8 @@ def get_next_standardized_reset_time(
|
|||
# Handle different time units
|
||||
if unit == "d":
|
||||
return _handle_day_reset(current_time, base_midnight, value, tz)
|
||||
elif unit == "w":
|
||||
return _handle_day_reset(current_time, base_midnight, value * 7, tz)
|
||||
elif unit == "h":
|
||||
return _handle_hour_reset(current_time, base_midnight, value)
|
||||
elif unit == "m":
|
||||
|
|
|
|||
|
|
@ -34,6 +34,17 @@ class TestStandardizedResetTime(unittest.TestCase):
|
|||
custom_day_result = get_next_standardized_reset_time("3d", base_time, "UTC")
|
||||
self.assertEqual(custom_day_result, custom_day_expected)
|
||||
|
||||
def test_week_based_resets(self):
|
||||
wednesday = datetime(2023, 5, 17, 15, 45, 0, tzinfo=timezone.utc)
|
||||
weekly_expected = datetime(2023, 5, 22, 0, 0, 0, tzinfo=timezone.utc)
|
||||
weekly_result = get_next_standardized_reset_time("1w", wednesday, "UTC")
|
||||
self.assertEqual(weekly_result, weekly_expected)
|
||||
|
||||
base_time = datetime(2023, 5, 15, 10, 30, 0, tzinfo=timezone.utc)
|
||||
two_week_expected = datetime(2023, 5, 29, 0, 0, 0, tzinfo=timezone.utc)
|
||||
two_week_result = get_next_standardized_reset_time("2w", base_time, "UTC")
|
||||
self.assertEqual(two_week_result, two_week_expected)
|
||||
|
||||
def test_hour_minute_second_resets(self):
|
||||
"""Test hour, minute, and second based reset durations"""
|
||||
# Base time: 2023-05-15 15:20:30 UTC (3:20:30 PM)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue