feat: use IANA timezone names instead of numeric offset

This commit is contained in:
rin.kagamine committed 2026-06-14 13:52:51 -04:00
1 parent 1a6e06c2bd
commit 34b64331bb
1 file changed
+11 -6
+11 -6
View File
@@ -5,12 +5,13 @@ author_url: https://rin.captcouch.xyz
description: Check LiteLLM proxy health + auth status and get cost breakdowns with configurable timerange. Two functions, that's it. description: Check LiteLLM proxy health + auth status and get cost breakdowns with configurable timerange. Two functions, that's it.
required_open_webui_version: 0.4.0 required_open_webui_version: 0.4.0
requirements: requests requirements: requests
version: 1.2.1 version: 1.2.2
licence: MIT licence: MIT
""" """
import requests import requests
from datetime import datetime, timedelta from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from typing import Optional from typing import Optional
@@ -34,9 +35,9 @@ class Tools:
default=True, default=True,
description="Default behavior for zero-spend model filtering. When True, models with sub-$0.001 spend are hidden by default and summarized. The per-call hide_zero_spend parameter can override this.", description="Default behavior for zero-spend model filtering. When True, models with sub-$0.001 spend are hidden by default and summarized. The per-call hide_zero_spend parameter can override this.",
) )
timezone_offset: int = Field( timezone: str = Field(
default=0, default="UTC",
description="Timezone offset from UTC in hours (e.g. -4 for EDT, -5 for EST). Used for natural language date resolution (today, yesterday).", description="IANA Timezone name (e.g. America/New_York, Europe/London, Asia/Tokyo). Used for natural language date resolution (today, yesterday).",
) )
def _headers(self) -> dict: def _headers(self) -> dict:
@@ -58,8 +59,12 @@ class Tools:
Falls back to passthrough if already YYYY-MM-DD or unrecognized. Falls back to passthrough if already YYYY-MM-DD or unrecognized.
""" """
date_str = date_str.strip().lower() date_str = date_str.strip().lower()
# Apply timezone offset to UTC now to get "local" today # Resolve "today" in the configured timezone
today = (datetime.utcnow() + timedelta(hours=self.valves.timezone_offset)).date() try:
today = datetime.now(ZoneInfo(self.valves.timezone)).date()
except Exception:
# Fallback to UTC if timezone is invalid
today = datetime.utcnow().date()
# Direct shortcuts # Direct shortcuts
if date_str == "today": if date_str == "today":