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

[CALCITE-6248] Illegal dates are accepted by casts #238

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

mihaibudiu
Copy link
Contributor

No description provided.

@mihaibudiu
Copy link
Contributor Author

@zstan this builds on top of your previous fix for a similar issue with timestamps.

* values for days and months, and accepts spaces around the value.
* @param s A string representing a date.
*/
private static void validateLenientDate(String s) {
Copy link

Choose a reason for hiding this comment

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

There is no problem using this method to verify, but this implementation only verifies DAY. Is it possible to use a more general verification method, such as:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
try {
    LocalDate date = LocalDate.parse(dateString, formatter);
    return true;
} catch (DateTimeParseException e) {
    return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does the exact same validation as the existing function validateDate.
So maybe we should improve that function too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a commit to validate month and year values.
Turns out year 0 is not legal in the Gregorian calendar, so I had to delete some tests that were using it.

@mihaibudiu
Copy link
Contributor Author

If CI passes I will merge this PR.

@mihaibudiu mihaibudiu merged commit c0cb4b7 into apache:main Apr 1, 2024
11 checks passed
@mihaibudiu mihaibudiu deleted the issue6248 branch April 1, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants