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

set start/end datetime to the unique datetime passed in api.Search #152

Merged
merged 3 commits into from
May 21, 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.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
4 changes: 2 additions & 2 deletions stac_pydantic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for a more verbose way (ref: #135 (review))


# Cast because pylance gets confused by the type adapter and annotated type
dates = cast(
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading