Skip to content

Commit

Permalink
fix: interpret naive datetimes as UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed May 14, 2024
1 parent 8236912 commit 57a5a26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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 57a5a26

Please sign in to comment.