Skip to content

Commit

Permalink
[CALCITE-6248] Illegal dates are accepted by casts
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
mihaibudiu committed Feb 14, 2024
1 parent 178ff82 commit 657e500
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ private static void fraction(StringBuilder buf, int scale, long ms) {
}

public static int dateStringToUnixDate(String s) {
validateDate(s, s);
int hyphen1 = s.indexOf('-');
int y;
int m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,12 @@ private static void assertThrows(Runnable runnable,
* Test exception is raised if date in inappropriate meaning.
*/
@Test public void testBrokenDate() {
// Test case for https://issues.apache.org/jira/browse/CALCITE-6248
// [CALCITE-6248] Illegal dates are accepted by casts
assertThrows(() -> DateTimeUtils.dateStringToUnixDate("2023-02-29"),
IllegalArgumentException.class,
is("Value of DAY field is out of range in '2023-02-29'"));

// 2023 is not a leap year
assertThrows(() ->
DateTimeUtils.timestampStringToUnixDate("2023-02-29 12:00:00.123"),
Expand Down

0 comments on commit 657e500

Please sign in to comment.