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

Should LocalDate be stored by default in UTC? #886

Closed
ps-feng opened this issue Apr 19, 2020 · 1 comment · Fixed by #1787
Closed

Should LocalDate be stored by default in UTC? #886

ps-feng opened this issue Apr 19, 2020 · 1 comment · Fixed by #1787
Labels

Comments

@ps-feng
Copy link

ps-feng commented Apr 19, 2020

When using date as a table column (Column<LocalDate>) the value saved to the DB depends on the timezone of the system. This means something like

SomeTable.insert {
    this[date] = LocalDate.parse("2020-01-01")
}

will be non-deterministic. The same code will insert a different value depending on the machine where it's run.

My suggestion would be to make dates use UTC by default.

EDIT: it seems this happened because I had created the column via regular SQL as a timetamptz (Postgres) so there was a mismatch. Even though JavaLocalDateColumnType's SQL type is DATE it continued to work, albeit incorrectly, not sure if this should be a bug or not.

@adamu
Copy link

adamu commented Feb 19, 2021

I've also encountered this.

Java's LocalDate and SQL's DATE are both timezone-free. So there should be no timezone conversion required.

However, JavaLocalDateColumnType converts to a java.sql.Date using the local timezone. This means that, for example, in UTC+n timezones a LocalDate of 1991-01-01 will be stored as 1990-12-31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants