Skip to content
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 @@ -27,7 +27,6 @@
import java.time.format.DateTimeParseException;

public class DateUtils {
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public static final int EMPTY_DATE_INT = 10000101;

public static String formatDate(int date) {
Expand All @@ -44,7 +43,7 @@ public static Integer parseDateExpressionToInt(String dateExpression) {
}
LocalDate date;
try {
date = LocalDate.parse(dateExpression, DATE_FORMATTER);
date = LocalDate.parse(dateExpression);
} catch (DateTimeParseException e) {
throw new DateTimeParseException(
"Invalid date format. Please use YYYY-MM-DD format.", dateExpression, 0);
Expand All @@ -61,7 +60,9 @@ public static Integer parseDateExpressionToInt(LocalDate localDate) {
}
if (localDate.getYear() < 1000 || localDate.getYear() > 9999) {
throw new DateTimeParseException(
"Year must be between 1000 and 9999.", localDate.format(DATE_FORMATTER), 0);
"Year must be between 1000 and 9999.",
localDate.format(DateTimeFormatter.ISO_LOCAL_DATE),
0);
}
return localDate.getYear() * 10000
+ localDate.getMonthValue() * 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public void testParseDateExpressionToInt_InvalidDate() {
});
}

@Test
public void testParseDateExpressionToInt_InvalidDate2() {
String dateExpression = "2023-04-31";
assertThrows(
DateTimeParseException.class,
() -> {
DateUtils.parseDateExpressionToInt(dateExpression);
});
}

@Test
public void testParseDateExpressionToInt_NullOrEmpty() {
assertThrows(
Expand Down
Loading