spring-projects / spring-projects/spring-data-relational
Loading a LocalDate results in timezones (wrongly) getting applied
@schauder is already working on this.
Since Jan 17, 2022.
- Dominant language
- Java
- Stars
- 827
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
Currently, using a java.time.LocalDate on an entity results in funny behaviour when loading it from the database (e.g. adding or removing a day depending on timezone), since the database result is converted to java.sql.Date before being converted to LocalDate, therefore adding in some timezone shenaningans. (See also https://github.com/spring-projects/spring-data-jdbc/issues/663#issuecomment-890974162, https://github.com/spring-projects/spring-data-jdbc/issues/663#issuecomment-895959933 and https://github.com/pgjdbc/pgjdbc/issues/2221.)
Example with application in UTC+2 time-zone:
- date to be saved (
java.time.LocalDate.toString()): "1000-01-01" - field in database (postgres
DATEtype): "1000-01-01" - result when loading entity via spring-data-jdbc (
java.time.LocalDate.toString()): "0999-12-31"
I may add a code example to reproduce once I find the time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.