-
Notifications
You must be signed in to change notification settings - Fork 7
99 datetimeinterval RFC 3339 #100
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
base: main
Are you sure you want to change the base?
99 datetimeinterval RFC 3339 #100
Conversation
"""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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like your code would support this, but I would also explicitly test the case of ../..
, which I believe should also be valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added. Also, added unit test for end before start.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
}
_ = 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("../..") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: this should fail, per prior comment
What I'm changing
make DatetimeInterval RFC 3339 compliant (open-ended date ranges)
Checklist
uv run pytest
uv run pre-commit run --all-files