-
Notifications
You must be signed in to change notification settings - Fork 851
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
fix: avoid timezone conversions when sending LocalDateTime to the database #2852
Conversation
61525f5
to
d29cc5d
Compare
This change brings back inconsistency of So |
ac25bff
to
4bce414
Compare
case Oid.TIMESTAMPTZ: | ||
return ts.toString(ts.toOffsetDateTimeBin(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This yields +00:00
OffsetDateTime
since PostgreSQL does not store and return the offset.
It causes the failure like
org.junit.ComparisonFailure: tstz -> getString, binary expected:<2005-01-01 1[5:00:00+03]> but was:<2005-01-01 1[2:00:00+00]>
Any thoughts on whether we should fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only solution to this is to not allow sending timestamptz in binary. Or we apply the client timezone to the received value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with "apply client timezone to the received value" (see withOffsetSameInstant
). It keeps compatibility regarding .getString()
which might be a nice thing to have.
fea1e3f
to
78636b7
Compare
String expected = localDateTime.atZone(zone) | ||
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) | ||
.replace('T', ' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the actual test for the feature. In other words, previously, the test used atZone
formatting of the local date time which was invalid, and it augmented the input date. That made the test to pass without issues. Now we avoid atZone
formatting, and we use the input value as is, and we test the output is the same.
…abase Previously, LocalDateTime was converted to OffsetDateTime using the default timezone, which made certain values unrepresentable. For instance, 2023-03-12T02:00 in America/New_York is hard to represent as it undergoes DST change. It does not change resultSet.getObject(int | string), and resultSet.getString(int | string) and those methods would still have issues when accessing timestamps like 2023-03-12T02:00 when the client time zone is America/New_York Co-authored-by: Kevin Wooten <kevin@wooten.com> Fixes pgjdbc#1390 Fixes pgjdbc#2850 Closes pgjdbc#1391
Previously, LocalDateTime was converted to OffsetDateTime using the default timezone, which made certain values unrepresentable. For instance, 2023-03-12T02:00 in America/New_York is hard to represent as it undergoes DST change.
It does not change resultSet.getObject(int | string), and resultSet.getString(int | string) and those methods would still have issues when accessing timestamps like 2023-03-12T02:00 when the client time zone is America/New_York
Fixes #1390
Fixes #2850
Closes #1391