Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LocalDate persisting dates as the day before #3248

Merged
merged 4 commits into from
Dec 5, 2024
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 @@ -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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to convert to java.sql.Date or else converter from core that converts to UTC will be used. And we need sql date anyway.

}
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
Loading