Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llm/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def llm_time() -> dict:

# Calculate offset
offset_seconds = -time.timezone if not is_dst else -time.altzone
offset_hours = offset_seconds // 3600
offset_minutes = (offset_seconds % 3600) // 60
abs_seconds = abs(offset_seconds)
offset_hours = abs_seconds // 3600
offset_minutes = (abs_seconds % 3600) // 60
sign = "+" if offset_seconds >= 0 else "-"

timezone_offset = (
f"UTC{'+' if offset_hours >= 0 else ''}{offset_hours:02d}:{offset_minutes:02d}"
)
timezone_offset = f"UTC{sign}{offset_hours:02d}:{offset_minutes:02d}"

return {
"utc_time": utc_time.strftime("%Y-%m-%d %H:%M:%S UTC"),
Expand Down
22 changes: 22 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,28 @@ def test_default_tool_llm_time():
}


def test_llm_time_timezone_offset_format(monkeypatch):
from unittest.mock import MagicMock

mock_tm = MagicMock()
mock_tm.tm_isdst = 0

# Simulate UTC-5 (EST): time.timezone = 18000 (seconds west of UTC)
monkeypatch.setattr(time, "timezone", 18000)
monkeypatch.setattr(time, "altzone", 14400)
monkeypatch.setattr(time, "localtime", lambda: mock_tm)
monkeypatch.setattr(time, "tzname", ("EST", "EDT"))
info = llm_time()
assert info["timezone_offset"] == "UTC-05:00"

# Simulate UTC+5:30 (IST): time.timezone = -19800
monkeypatch.setattr(time, "timezone", -19800)
monkeypatch.setattr(time, "altzone", -19800)
monkeypatch.setattr(time, "tzname", ("IST", "IST"))
info = llm_time()
assert info["timezone_offset"] == "UTC+05:30"


def test_incorrect_tool_usage():
model = llm.get_model("echo")

Expand Down