Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret naive datetimes as UTC #686

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading