spring-projects / spring-projects/spring-data-relational

Loading a LocalDate results in timezones (wrongly) getting applied

Open
#1,127 1 comment 0 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Jan 17, 2022.

in: mapping theme: date-time type: bug
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 DATE type): "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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.