Skip to content

Commit 3e02053

Browse files
authored
fix: interpret naive datetimes as UTC (#686)
1 parent 5560960 commit 3e02053

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Fixed
1111

1212
- Update `requires-python` in metadata to require >= 3.9 ([#684](https://github.com/stac-utils/pystac-client/pull/684))
13+
- Interpret naive datetimes as UTC [#686](https://github.com/stac-utils/pystac-client/pull/686)
1314

1415
## [v0.7.7]
1516

pystac_client/item_search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ def _format_bbox(value: Optional[BBoxLike]) -> Optional[BBox]:
438438

439439
@staticmethod
440440
def _to_utc_isoformat(dt: datetime_) -> str:
441-
dt = dt.astimezone(timezone.utc)
441+
if dt.tzinfo is not None:
442+
dt = dt.astimezone(timezone.utc)
442443
dt = dt.replace(tzinfo=None)
443444
return f'{dt.isoformat("T")}Z'
444445

tests/test_item_search.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,12 @@ def test_multiple_collections() -> None:
826826
)
827827
collections = set(item.collection_id for item in search.items())
828828
assert collections == {"sentinel-2-l2a", "landsat-c2-l2"}
829+
830+
831+
def test_naive_datetime() -> None:
832+
search = ItemSearch(
833+
url="https://earth-search.aws.element84.com/v1/search",
834+
datetime=datetime(2024, 5, 14, 4, 25, 42, tzinfo=None),
835+
method="POST",
836+
)
837+
assert search.get_parameters()["datetime"] == "2024-05-14T04:25:42Z"

0 commit comments

Comments
 (0)