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

Support for Range of OffsetDateTime #96

Open
tipenull opened this issue May 9, 2019 · 6 comments
Open

Support for Range of OffsetDateTime #96

tipenull opened this issue May 9, 2019 · 6 comments

Comments

@tipenull
Copy link

tipenull commented May 9, 2019

Currently only Range is mapped to tstzrange.
However, the default java type for timestamptz is OffsetDateTime rather than LocalDateTime - which seems adequate since timestamptz doesn't actually carry a time zone, but an offset.
Hence, I'd expect Range to be mapped to tstzrange.

@vladmihalcea
Copy link
Owner

vladmihalcea commented May 9, 2019

However, the default java type for timestamptz is OffsetDateTime rather than LocalDateTime

Where did you get this from? There is no default Java mapping between PostgreSQL column types and Java types.

since timestamptz doesn't actually carry a time zone, but an offset.

That's also not true. The timestamptz column type is a timezone-aware type. When you insert a value into a timestamptz column, PostgreSQL will convert the timestamptz value to its UTC equivalent.

Hence, I'd expect Range to be mapped to tstzrange.

Which is already the case for a Range<ZonedDateTime>.

@tipenull
Copy link
Author

tipenull commented May 9, 2019

Where did you get this from? There is no default Java mapping between PostgreSQL column types and Java types.

It's specified for the PostgreSQL JDBC driver (https://jdbc.postgresql.org/documentation/head/8-date-time.html). 'Default' was definitely too broad of a phrasing.

Which is already the case for a Range.

I meant to specify Range. Funny that I forgot that of all things.

@vladmihalcea
Copy link
Owner

vladmihalcea commented May 9, 2019

In that case, you should provide a Pull Request with a fix. I'll review it once you are done.

@vladmihalcea vladmihalcea reopened this May 9, 2019
@nstdio
Copy link
Contributor

nstdio commented May 9, 2019

@tipenull I think you are right

Here is quote from documentation: Note that ZonedDateTime, Instant and OffsetTime / TIME WITH TIME ZONE are not supported and here is why.

@nstdio
Copy link
Contributor

nstdio commented May 10, 2019

@vladmihalcea @tipenull

I was trying to figure out how to replace the ZonedDateTime to OffsetDateTime of it turn's out that it no so easy to do it with backward compatibility. Obviously we can deprecate all things connected with ZonedDateTime and provide OffsetDateTime equivalents, but if we change mapping for tstzrange and return Range<OffsetDateTime> instead of Range<ZonedDateTime> users can easily experience ClassCastException.

After few hours of digging it seems there is no way to backward compatible change.

If there way to obtain the generic type from user defined entity, we can check whether user binds tstzrange to Range<ZonedDateTime> and log warning, like don't use ZoneDateTime, rebind your field to OffsetDateTime.

@vladmihalcea
Copy link
Owner

You can add a Configuration and leave the default as-is. But if you specify the config, you switch to using OffsetDateTime instead.

Check out the JSON Types for more details as they have some configs that can be applied.

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

No branches or pull requests

3 participants