Skip to content

Commit

Permalink
Fix LocalDate persisting dates as the day before (#3248)
Browse files Browse the repository at this point in the history
* Reproducing issue with LocalDate going one day back

* Verify localDate values are saved and read correctly

* Sonar warning
  • Loading branch information
radovanradic authored Dec 5, 2024
1 parent 86a54bb commit 06c93d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ DataConversionServiceImpl build(@NonNull BeanContext beanContext) {
// ZonedDateTime
addZonedConvertorsConvertors(conversionService, ZonedDateTime.class, Function.identity());

// LocalDate
conversionService.addConverter(LocalDate.class, java.sql.Date.class, java.sql.Date::valueOf);

// LocalTime
conversionService.addConverter(LocalTime.class, Timestamp.class, localTime -> Timestamp.valueOf(localTime.atDate(LocalDate.now())));
conversionService.addConverter(LocalTime.class, Instant.class, localTime -> localTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()).toInstant());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ default QueryStatement<PS, IDX> setDynamic(
if (value instanceof Date date) {
return setDate(statement, index, date);
} else {
return setDate(statement, index, convertRequired(value, Date.class));
return setDate(statement, index, convertRequired(value, java.sql.Date.class));
}
case TIMESTAMP:
Instant instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ abstract class AbstractRepositorySpec extends Specification {
retrievedBook.offsetDateTime == book.offsetDateTime
retrievedBook.dateCreated == book.dateCreated
retrievedBook.dateUpdated == book.dateUpdated
retrievedBook.localDate == book.localDate

// stored as a DATE type without time
// retrievedBookProj.date == book.date
Expand Down

0 comments on commit 06c93d2

Please sign in to comment.