Draft
Conversation
jkeifer
reviewed
Apr 19, 2025
| """Test the datetime interval validator.""" | ||
| dt1 = DatetimeInterval.__metadata__[0].func("2025-04-01T00:00:00Z/2025-04-01T23:59:59Z") | ||
| dt2 = DatetimeInterval.__metadata__[0].func("2025-04-01T00:00:00Z/..") | ||
| dt3 = DatetimeInterval.__metadata__[0].func("../2025-04-01T23:59:59Z") |
Member
There was a problem hiding this comment.
Looks like your code would support this, but I would also explicitly test the case of ../.., which I believe should also be valid.
Contributor
Author
There was a problem hiding this comment.
Added. Also, added unit test for end before start.
philvarner
reviewed
Apr 24, 2025
| start_str, end_str = value.split("/", 1) | ||
| start = None if start_str == ".." else datetime.fromisoformat(start_str) | ||
| end = None if end_str == ".." else datetime.fromisoformat(end_str) | ||
| value = (start, end) |
Contributor
There was a problem hiding this comment.
issue: one of the intervals has to closed, e.g., ../.. and / are not allowed. The code from stac-server (that I believe to be correct) is:
if (datetime) {
const datetimeUpperCase = datetime.toUpperCase()
const [start, end, ...rest] = datetimeUpperCase.split('/')
if (rest.length) {
throw new ValidationError(
'datetime value is invalid, too many forward slashes for an interval'
)
} else if ((!start && !end)
|| (start === '..' && end === '..')
|| (!start && end === '..')
|| (start === '..' && !end)
) {
throw new ValidationError(
'datetime value is invalid, at least one end of the interval must be closed'
)
} else {
const startDateTime = (start && start !== '..') ? rfc3339ToDateTime(start) : undefined
const endDateTime = (end && end !== '..') ? rfc3339ToDateTime(end) : undefined
validateStartAndEndDatetimes(startDateTime, endDateTime)
}
return datetimeUpperCase
}
philvarner
reviewed
Apr 24, 2025
| _ = DatetimeInterval.__metadata__[1].func(dt2) | ||
| dt3 = DatetimeInterval.__metadata__[0].func("../2025-04-01T23:59:59Z") | ||
| _ = DatetimeInterval.__metadata__[1].func(dt3) | ||
| dt4 = DatetimeInterval.__metadata__[0].func("../..") |
Contributor
There was a problem hiding this comment.
issue: this should fail, per prior comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I'm changing
make DatetimeInterval RFC 3339 compliant (open-ended date ranges)
Checklist
uv run pytestuv run pre-commit run --all-files