diff --git a/src/main/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverter.java b/src/main/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverter.java index 7504dd65..d75ee8c3 100644 --- a/src/main/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverter.java +++ b/src/main/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverter.java @@ -15,12 +15,17 @@ public class StringToDateTimeConverter { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withLocale(Locale.KOREA); private static final DateTimeFormatter dateTimeTFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS").withLocale(Locale.KOREA); + private static final int MAX_DATE_TIME_LENGTH = 26; public static LocalDateTime convert(String dateTime) { if (dateTime == null || dateTime.isBlank()) { throw new IllegalArgumentException("Invalid date time format: " + dateTime); } + if (dateTime.length() > MAX_DATE_TIME_LENGTH) { + dateTime = dateTime.substring(0, MAX_DATE_TIME_LENGTH); + } + if (isDateTime(dateTime)) { return LocalDateTime.parse(dateTime, dateTimeFormatter); } diff --git a/src/test/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverterTest.java b/src/test/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverterTest.java index 3edc0229..ae9e1671 100644 --- a/src/test/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverterTest.java +++ b/src/test/java/com/kustacks/kuring/common/utils/converter/StringToDateTimeConverterTest.java @@ -42,7 +42,9 @@ void date_time_convert_fail(String dateTime) { private static Stream stringLocalDateInputProvider() { return Stream.of( Arguments.of("2023-04-03 00:00:12", LocalDateTime.of(2023, 4, 3, 0, 0, 12)), - Arguments.of("2024-08-03T20:01:27.454996", LocalDateTime.of(2024, 8, 3, 20, 1, 27)) + Arguments.of("2024-08-03T20:01:27.454996", LocalDateTime.of(2024, 8, 3, 20, 1, 27)), + Arguments.of("2024-08-04T21:57:23.1166969", LocalDateTime.of(2024, 8, 4, 21, 57, 23)), + Arguments.of("2024-08-04T21:57:23.116696917", LocalDateTime.of(2024, 8, 4, 21, 57, 23)) ); } }