Skip to content

Commit

Permalink
fix: attributeConverter milli second 길이가 두개인 경우도 반영 (#348)
Browse files Browse the repository at this point in the history
* fix: mili second 길이가 두개인 경우도 반영

* fix: authExpiredAt 시간 변경

* chore: datetimeformatter 변수명 변경

(cherry picked from commit 2044f66)
  • Loading branch information
seongjae6751 authored and Choi-JJunho committed May 9, 2024
1 parent 8641db1 commit b3cc8ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Student toStudent(PasswordEncoder passwordEncoder, Clock clock) {
.isDeleted(false)
.userType(UserType.STUDENT)
.authToken(UUID.randomUUID().toString())
.authExpiredAt(LocalDateTime.now(clock).plusHours(1))
.authExpiredAt(LocalDateTime.now(clock).plusHours(10))
.build();

return Student.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
@Converter(autoApply = true)
public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDateTime, String> {

private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.SSS]");
private final DateTimeFormatter formatterWithThreeMillis = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.SSS]");
private final DateTimeFormatter formatterWithTwoMillis = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS");

@Override
public String convertToDatabaseColumn(LocalDateTime localDateTime) {
if (localDateTime == null) {
return null;
}
return localDateTime.format(formatter);
return localDateTime.format(formatterWithThreeMillis);
}

@Override
public LocalDateTime convertToEntityAttribute(String dbData) {
if (dbData == null) {
return null;
}
return LocalDateTime.parse(dbData, formatter);

if (dbData.matches(".*\\.\\d{3}$")) {
return LocalDateTime.parse(dbData, formatterWithThreeMillis);
} else {
return LocalDateTime.parse(dbData, formatterWithTwoMillis);
}
}
}

0 comments on commit b3cc8ec

Please sign in to comment.