Skip to content

Commit

Permalink
fix: interpret naive datetimes as UTC (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored May 15, 2024
1 parent 5560960 commit 3e02053
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 2 additions & 1 deletion pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
9 changes: 9 additions & 0 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 3e02053

Please sign in to comment.