feat: use IANA timezone names instead of numeric offset
This commit is contained in:
1 parent
1a6e06c2bd
commit
34b64331bb
1 file changed
+11
-6
+11
-6
@@ -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.
|
||||
required_open_webui_version: 0.4.0
|
||||
requirements: requests
|
||||
version: 1.2.1
|
||||
version: 1.2.2
|
||||
licence: MIT
|
||||
"""
|
||||
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
|
||||
@@ -34,9 +35,9 @@ class Tools:
|
||||
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.",
|
||||
)
|
||||
timezone_offset: int = Field(
|
||||
default=0,
|
||||
description="Timezone offset from UTC in hours (e.g. -4 for EDT, -5 for EST). Used for natural language date resolution (today, yesterday).",
|
||||
timezone: str = Field(
|
||||
default="UTC",
|
||||
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:
|
||||
@@ -58,8 +59,12 @@ class Tools:
|
||||
Falls back to passthrough if already YYYY-MM-DD or unrecognized.
|
||||
"""
|
||||
date_str = date_str.strip().lower()
|
||||
# Apply timezone offset to UTC now to get "local" today
|
||||
today = (datetime.utcnow() + timedelta(hours=self.valves.timezone_offset)).date()
|
||||
# Resolve "today" in the configured timezone
|
||||
try:
|
||||
today = datetime.now(ZoneInfo(self.valves.timezone)).date()
|
||||
except Exception:
|
||||
# Fallback to UTC if timezone is invalid
|
||||
today = datetime.utcnow().date()
|
||||
|
||||
# Direct shortcuts
|
||||
if date_str == "today":
|
||||
|
||||
Reference in new issue
Block a user