diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ffb7e10..209f055 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -13,6 +13,7 @@ - use `StacBaseModel` as base model for `Asset` model (#148, @vincentsarago) - add `license` in `StacCommonMetadata` model (#147, @vincentsarago) - make `limit` optional in `api.Search` model (#150, @vincentsarago) +- set `start/end datetime` to the datetime value when passing only one value in `api.Search` (#152, @vincentsarago) 3.0.0 (2024-01-25) ------------------ diff --git a/stac_pydantic/api/search.py b/stac_pydantic/api/search.py index c68fd60..57cfac0 100644 --- a/stac_pydantic/api/search.py +++ b/stac_pydantic/api/search.py @@ -108,9 +108,9 @@ def validate_datetime(cls, value: str) -> str: "Invalid datetime range. Too many values. Must match format: {begin_date}/{end_date}" ) - # If there is only one date, insert a None for the start date + # If there is only one date, duplicate to use for both start and end dates if len(values) == 1: - values.insert(0, None) + values = [values[0], values[0]] # Cast because pylance gets confused by the type adapter and annotated type dates = cast( diff --git a/tests/api/test_search.py b/tests/api/test_search.py index 95899ab..1615987 100644 --- a/tests/api/test_search.py +++ b/tests/api/test_search.py @@ -58,7 +58,7 @@ def test_temporal_search_single_tailed(): utcnow = datetime.now(timezone.utc) utcnow_str = utcnow.isoformat() search = Search(collections=["collection1"], datetime=utcnow_str) - assert search.start_date is None + assert search.start_date == utcnow assert search.end_date == utcnow