Problems with Java OffsetDateTime #3228
Replies: 4 comments 8 replies
-
@martinwyser thanks for the report, I can look into this tomorrow. |
Beta Was this translation helpful? Give feedback.
-
@martinwyser OK, REL42.2.6...REL42.2.7#diff-21e3023c84d9d5fb4f5f04678a094fce6ab5af36a5e73fdfaf495646f3b720d5R485 we added toOffsetDateTime in this PR https://github.com/pgjdbc/pgjdbc/pull/1539/files This is technically correct. If you change your code to use LocalDateTime everything works as expected, or if you change your data type to timestamptz it also works as expected. This is consistent with the mapping of LocalDateTime <-> Timestamp without time zone Since LocalDateTime does not have a time zone and OffsetDateTime does. Regards Dave |
Beta Was this translation helpful? Give feedback.
-
But you are using Timestamp without Time Zone as the data type.
I think you need to either change your data type to timestamp with timezone or use LocalDateTime You should know that even with
|
Beta Was this translation helpful? Give feedback.
-
@davecramer Thanks for the hint. I am already doing that. In this case, the combination of OffsetDateTime and timestamp was chosen to avoid conversions. I have looked at this in more detail, and the difference between 42.2.6 and ...7 boils In 42.2.6, the String is converted into a Timestamp using a Calendar for the local timezone (+1H).
and then on line 600:
This is then converted into an OffsetDateTime as a UTC time in PgResultSet.java#L3372:
So, the string received from the server is taken to be in time zone of the client, which happens in getDefaultCalendar(); In 42.2.7, the string is parsed with an offset of 0, and converted directly into an OffsetDateTime TimestampUtils.java#506
and then on line 512:
This is a breaking change, and I think it is not ok. There is also no use supporting OffsetDateTime for timestamp fields if it does not work. Also, the fact whether there is conversion to or from a timezone should depend on the type of the database field, not on the Java type. Anyway, thanks again for the help! I appreciate your work a lot! |
Beta Was this translation helpful? Give feedback.
-
Hi everybody
I am putting OffsetDateTime values into timestamp columns, and values I read back are different. The behaviour depends on the driver version. I have an example below.
Upto to 42.2.6, the behaviour is consistent, I get back what I write. 42.2.7, 42.3...., 42.4... get values back with an offset which depends on the current systems timezone. The behaviour does not depend on the server version, I tested with 13.7 and also some 14 and 15 versions.
Here is my "test". It assumes a postgres on localhost:5555:
Here is sample output:
Beta Was this translation helpful? Give feedback.
All reactions