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"