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
14 changes: 14 additions & 0 deletions tests/tools/builtin_tools/test_datetime_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ def test_diff_zero():
assert result["human"] == "0:00:00"


@pytest.mark.parametrize(
("start", "end", "seconds", "human"),
[
("2026-03-08 01:30:00", "2026-03-08 03:30:00", 3600, "1:00:00"),
("2026-11-01 00:30:00", "2026-11-01 02:30:00", 10800, "3:00:00"),
],
)
def test_diff_reports_elapsed_time_across_dst(start, end, seconds, human):
result = datetime_tool("diff", value=start, value2=end, timezone="America/New_York")
assert result["seconds"] == seconds
assert result["days"] == pytest.approx(seconds / 86400)
assert result["human"] == human


def test_diff_negative_seconds():
result = datetime_tool(
"diff",
Expand Down
5 changes: 4 additions & 1 deletion veadk/tools/builtin_tools/datetime_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def _action_diff(value: str | None, value2: str | None, timezone: str | None) ->
start = _parse(value, timezone)
end = _parse(value2, timezone)
delta = end - start
if start.tzinfo is end.tzinfo:
# Python subtraction ignores offset changes when tzinfo is shared.
delta += start.utcoffset() - end.utcoffset()
seconds = delta.total_seconds()
return {
"seconds": seconds,
Expand Down Expand Up @@ -209,7 +212,7 @@ def datetime(
"""Work with dates and times, including timezone conversions.

Use this tool for the current time, parsing or formatting a timestamp,
converting a timestamp between timezones, computing the difference between
converting a timestamp between timezones, computing the elapsed time between
two timestamps, or adding a duration. Timestamps without an explicit offset
use ``timezone`` (default UTC).

Expand Down