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

Handle MySQL Year data type with value <=1900 and >2155 #5193

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ private Long parseDateTimeStrAsEpochMillis(final String dateTimeStr) {
private Long handleYear(final String yearStr) {
try {
// MySQL YEAR values are typically four-digit numbers (e.g., 2024).
return Long.parseLong(yearStr);
final long year = Long.parseLong(yearStr);

// MySQL converts values in 1- or 2-digit strings in the range '0' to '99' to YYYY format
// MySQL YEAR values in YYYY format are with a range of 1901 to 2155. Outside this range the value is 0.
if (year <= 1900 || year > 2155) {
return 0L;
}

return year;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid year format: " + yearStr, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ void handle_withYearType_returnsCorrectEpochMillis(String input, long expected)
private static Stream<Arguments> provideYearTestCases() {
return Stream.of(
Arguments.of("2023", 2023),
Arguments.of("1900", 1900),
Arguments.of("1997", 1997)
Arguments.of("1900", 0),
Arguments.of("1997", 1997),
Arguments.of("1889", 0),
Arguments.of("1901", 1901),
Arguments.of("2155", 2155),
Arguments.of("2156", 0),
Arguments.of("3015", 0)
);
}

Expand Down
Loading