diff --git a/infrahub_sdk/timestamp.py b/infrahub_sdk/timestamp.py index fb07f076..15a2d18b 100644 --- a/infrahub_sdk/timestamp.py +++ b/infrahub_sdk/timestamp.py @@ -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 @@ -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)) diff --git a/tests/unit/sdk/test_timestamp.py b/tests/unit/sdk/test_timestamp.py index 3f1f3165..d147e0fb 100644 --- a/tests/unit/sdk/test_timestamp.py +++ b/tests/unit/sdk/test_timestamp.py @@ -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")