From cc3ea1fb08387a511b7cc243613df29d41b97062 Mon Sep 17 00:00:00 2001 From: Srivatsa03 Date: Sat, 22 Aug 2026 23:40:03 -0500 Subject: [PATCH] docs(cost): state that a naive off-peak current_time is read as UTC An aware value is converted, a naive one is taken to already be UTC rather than localised. Nothing signals the difference, so a caller passing datetime.now() instead of datetime.now(timezone.utc) shifts every window by the host's offset and bills silently wrong. Say so where a caller will read it. Reported by @xyzs996 in review. --- litellm/litellm_core_utils/llm_cost_calc/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.py index 30c25253eea..21680129ed4 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/utils.py +++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py @@ -298,6 +298,10 @@ def _is_within_off_peak_window(off_peak_hours_utc: str | Sequence[str], current_ with multiple daily windows (e.g. ["16:30-00:30", "04:00-06:00"]). A window may wrap past midnight, and a window whose start equals its end covers the whole day. The start is inclusive and the end is exclusive; malformed windows are ignored. + + An aware current_time is converted to UTC. A naive one is taken to already be UTC rather + than being localised, so callers must pass datetime.now(timezone.utc), never datetime.now(), + or every window shifts by the host's offset. """ reference: Final = current_time if current_time is not None else datetime.now(timezone.utc) now: Final = (reference.astimezone(timezone.utc) if reference.tzinfo is not None else reference).time()