Skip to content

Commit

Permalink
fix(StringToDateTimeConverter): Milli-second 부분은 6자리 까지만 지원
Browse files Browse the repository at this point in the history
  • Loading branch information
zbqmgldjfh committed Aug 4, 2024
1 parent 9e17236 commit e26cc70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ void date_time_convert_fail(String dateTime) {
private static Stream<Arguments> 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))
);
}
}

0 comments on commit e26cc70

Please sign in to comment.