diff --git a/CHANGELOG.md b/CHANGELOG.md index c548b17b..4a8f8aca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Update `requires-python` in metadata to require >= 3.9 ([#684](https://github.com/stac-utils/pystac-client/pull/684)) +- Interpret naive datetimes as UTC [#686](https://github.com/stac-utils/pystac-client/pull/686) ## [v0.7.7] diff --git a/pystac_client/item_search.py b/pystac_client/item_search.py index e8fcc7a5..de9b51c5 100644 --- a/pystac_client/item_search.py +++ b/pystac_client/item_search.py @@ -438,7 +438,8 @@ def _format_bbox(value: Optional[BBoxLike]) -> Optional[BBox]: @staticmethod def _to_utc_isoformat(dt: datetime_) -> str: - dt = dt.astimezone(timezone.utc) + if dt.tzinfo is not None: + dt = dt.astimezone(timezone.utc) dt = dt.replace(tzinfo=None) return f'{dt.isoformat("T")}Z' diff --git a/tests/test_item_search.py b/tests/test_item_search.py index cca9d97b..a198181e 100644 --- a/tests/test_item_search.py +++ b/tests/test_item_search.py @@ -826,3 +826,12 @@ def test_multiple_collections() -> None: ) collections = set(item.collection_id for item in search.items()) assert collections == {"sentinel-2-l2a", "landsat-c2-l2"} + + +def test_naive_datetime() -> None: + search = ItemSearch( + url="https://earth-search.aws.element84.com/v1/search", + datetime=datetime(2024, 5, 14, 4, 25, 42, tzinfo=None), + method="POST", + ) + assert search.get_parameters()["datetime"] == "2024-05-14T04:25:42Z"