Skip to content

Commit e59e6a5

Browse files
authored
Merge pull request #295 from opsmill/dga-20250305-OffsetDateTime
Add support for Offset DateTime to Timestamp
2 parents fc93bfe + c7311e2 commit e59e6a5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

infrahub_sdk/timestamp.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from datetime import datetime, timezone
66
from typing import Literal
77

8-
from whenever import Date, Instant, LocalDateTime, Time, ZonedDateTime
8+
from whenever import Date, Instant, LocalDateTime, OffsetDateTime, Time, ZonedDateTime
99

1010
from .exceptions import TimestampFormatError
1111

@@ -60,6 +60,12 @@ def _parse_string(cls, value: str) -> ZonedDateTime:
6060
except ValueError:
6161
pass
6262

63+
try:
64+
offset_date_time = OffsetDateTime.parse_common_iso(value)
65+
return offset_date_time.to_tz("UTC")
66+
except ValueError:
67+
pass
68+
6369
try:
6470
date = Date.parse_common_iso(value)
6571
local_date = date.at(Time(12, 00))

tests/unit/sdk/test_timestamp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_parse_string():
3737
assert Timestamp._parse_string("10s")
3838
assert Timestamp._parse_string("2025-01-02")
3939
assert Timestamp._parse_string("2024-06-04T03:13:03.386270")
40-
40+
assert Timestamp._parse_string("2025-03-05T18:01:52+01:00")
4141
with pytest.raises(TimestampFormatError):
4242
Timestamp._parse_string("notvalid")
4343

0 commit comments

Comments
 (0)