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

Search start_date property does not support single-value for datetime #145

Closed
avbentem opened this issue May 14, 2024 · 3 comments · Fixed by #152
Closed

Search start_date property does not support single-value for datetime #145

avbentem opened this issue May 14, 2024 · 3 comments · Fixed by #152

Comments

@avbentem
Copy link
Contributor

avbentem commented May 14, 2024

The datetime attribute of a search request is defined to be an exact datetime, or a range with possible open ends on either side:

Parameter Type Source API Description
...
datetime string OAFeat Single date+time, or a range ('/' separator), formatted to RFC 3339, section 5.6. Use double dots .. for open date ranges.
...

But today, the start_date and end_date properties are implemented as:

@property
def start_date(self) -> Optional[dt]:
values = (self.datetime or "").split("/")
if len(values) == 1:
return None
if values[0] == ".." or values[0] == "":
return None
return parse_rfc3339(values[0])
@property
def end_date(self) -> Optional[dt]:
values = (self.datetime or "").split("/")
if len(values) == 1:
return parse_rfc3339(values[0])
if values[1] == ".." or values[1] == "":
return None
return parse_rfc3339(values[1])

This implies that for a single value, start_date is left empty and only end_date is set:

datetime start_date end_date
2012-07-02T00:00:00Z None 2012-07-02 00:00
2012-07-02T00:00:00Z/.. 2012-07-02 00:00 None
../2012-07-03T23:59:59Z None 2012-07-03 00:00

I very much assume for a single datetime (the first case above) both start_date and end_date should be set to the same value?

(I can submit a PR if this is indeed a bug. It's just line 50 that should be changed from return None into return parse_rfc3339(values[0]). EDIT: also def validate_datetime would need a fix; see below.)

@avbentem
Copy link
Contributor Author

avbentem commented May 14, 2024

@jonhealy1 I see your 👍 but now I also ran into this:

@field_validator("datetime")
@classmethod
def validate_datetime(cls, v: str) -> str:
if "/" in v:
values = v.split("/")
else:
# Single date is interpreted as end date
values = ["..", v]

So, its implementation seems quite specific. Also in the follwing PR the same behavior is kept, but maybe that's unintentional:

https://github.com/stac-utils/stac-pydantic/pull/135/files#diff-cedfbbe7e0d06171e4f3cdfab0c02e1712111610dc9419080077b4d15a1c3d85R109-R111

Related discussion: stac-utils/stac-fastapi#688

@vincentsarago
Copy link
Member

vincentsarago commented May 21, 2024

note, this is the same issue as #79

@avbentem

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants