planet-client-python
planet-client-python copied to clipboard
create helper function for converting datetime string from API descriptions into datetime
Support usage of the API description datetime information, provided as an RFC 3339 string, by creating a helper function for converting that string into a datetime object.
e.g. something like:
add to io.py
from datetime import datetime
DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
def to_datetime(rfc3339: str) -> datetime:
"""Convert an RFC 3339 string from an API response to a datetime."""
return datetime.strptime(rfc3339, DATE_FORMAT)
add to test_io.py
from datetime import datetime
@pytest.mark.parametrize(
"rfc3339, expected",
[("2021-02-03T01:40:07.359Z", datetime(2021, 2, 3, 1, 40, 7, 359000)), ... ])
def test_to_datetime(rfc3339, expected):
assert io.to_datetime(rfc3339) == expected