spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Loading a LocalDate results in timezones (wrongly) getting applied

Open nanella opened this issue 4 years ago • 1 comments

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.

nanella avatar Jan 13 '22 10:01 nanella

As so often with dates there are more then one thing coming together here:

  1. The problem you describe is probably related to really funny stuff the date conversion does for dates in the distant past: https://stackoverflow.com/q/60429118/66686. And this seems to make it also depend on the exact timezone, not just the offset from UTC. We need to fix that. This issue should track that work.
  2. The conversion to java.sql.Timestamp really shouldn't happen after registering LocalDate as a simple datatype. But it still does. This will be tracked by #1136

schauder avatar Jan 20 '22 13:01 schauder