Skip to content
Merged
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
8 changes: 7 additions & 1 deletion infrahub_sdk/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime, timezone
from typing import Literal

from whenever import Date, Instant, LocalDateTime, Time, ZonedDateTime
from whenever import Date, Instant, LocalDateTime, OffsetDateTime, Time, ZonedDateTime

from .exceptions import TimestampFormatError

Expand Down Expand Up @@ -60,6 +60,12 @@ def _parse_string(cls, value: str) -> ZonedDateTime:
except ValueError:
pass

try:
offset_date_time = OffsetDateTime.parse_common_iso(value)
return offset_date_time.to_tz("UTC")
except ValueError:
pass

try:
date = Date.parse_common_iso(value)
local_date = date.at(Time(12, 00))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/sdk/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_parse_string():
assert Timestamp._parse_string("10s")
assert Timestamp._parse_string("2025-01-02")
assert Timestamp._parse_string("2024-06-04T03:13:03.386270")

assert Timestamp._parse_string("2025-03-05T18:01:52+01:00")
with pytest.raises(TimestampFormatError):
Timestamp._parse_string("notvalid")

Expand Down