-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: timestamp parsing * tests: fix CI * style: fix docstring
- Loading branch information
Showing
5 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Utility functions for working with datetime objects.""" | ||
from datetime import datetime | ||
|
||
|
||
def from_isoformat(date_str: str) -> datetime: | ||
"""Parse a date string in ISO 8601 format and returns a datetime object. | ||
Our new Pydantic 2.0 API returns with the `Z` suffix, but the old one returns with `+00:00` | ||
Python versions < 3.12 don't support the `Z` suffix, so we need to replace it with `+00:00` | ||
""" | ||
date_str = date_str.replace("Z", "+00:00") | ||
return datetime.fromisoformat(date_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from datetime import datetime, timezone | ||
|
||
import pytest | ||
|
||
from deepset_cloud_sdk._utils.datetime import from_isoformat | ||
|
||
|
||
class TestFromIsoformat: | ||
@pytest.mark.parametrize( | ||
"input", | ||
[ | ||
"2024-02-03T08:10:10.335884Z", | ||
"2024-02-03T08:10:10.335884+00:00", | ||
], | ||
) | ||
def test_fromisoformat(self, input: str) -> None: | ||
assert from_isoformat(input) == datetime(2024, 2, 3, 8, 10, 10, 335884).replace(tzinfo=timezone.utc) |