-
Notifications
You must be signed in to change notification settings - Fork 427
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 getObject() conversion of DATETIMEOFFSET to LocalDateTime #2204
Conversation
As is, this would be a breaking change that would never be merged. That said, before you spend more time on the code, if you want to push for this change, ways forward would include a connection property that maintained existing behavior and made this behavior opt-in. Additionally, justifying this change by comparing behavior with other JDBC drivers, like jTDS, MySQL's JDBC driver, PostgreSQL, and Oracle. If the MS JDBC driver is the outlier and all others behave as you are proposing, that gives your position more strength. Regards, |
I've done a brief survey and determined the following:
I'd be fine with saying the current behavior is the default, and my proposed behavior requires a connection property. If I update this PR to do that, do you think it would get merged? |
Just to be transparent, adding public surface area (public APIs, connection properties, etc.) has a non-zero maintenance cost. So we try to get justification for adding those and see if there are others who desire the same functionality. (Of course, submitting the functionality yourself certainly makes it more likely to be accepted. 😄) That said, what is the use case for using the driver this way? When calling setObject(LocalDateTime) against a DATETIMEOFFSET column, the driver assumes the local offset, so rather than simply ignoring and truncating the offset from the database value, the current behavior of returning the time in the local offset seems perfectly reasonable. If you are using DATETIMEOFFSET in the database, how come you aren't using OffsetDateTime on the Java side? If you want to ignore the offset for some reason, why not just call getObject(col, OffsetDateTime.class) then OffsetDateTime#toLocalDate()? If your app doesn't need offset at all, why not use a DATETIME2 column? Regards, |
The current behavior might be reasonable, but it also violates the principle of least surprise. It's the only context I've seen where this behavior exists. As I said when I opened this PR, both
I can, at least in some code where I have direct control of this. There are other cases where a third-party library is interrogating the ResultSet and I can't do that. And, at the risk of repeating myself: as a Java developer, I expected that
There are some cases in the application where the time zone matters, and other cases where we want the local time. I opened this PR mainly because the current behavior is surprising to me. But if nobody else agrees, I'll stop arguing and close it. |
We discussed it and we are okay with adding this feature. To summarize the changes required:
CC: @lilgreenbird, @Jeffery-Wasty, @tkyc to chime in if I'm forgetting anything. |
Okay, sounds good. I'm about to go on vacation so it'll be a few weeks before I get back to this. |
@microsoft-github-policy-service agree company="Scientific Games" I named the connection property |
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.
we discussed with product mgmt your suggestion however IgnoreOffsetOnDateTimeOffsetConversion
is preferred.
This is ready to be reviewed. |
Currently, if you have a DATETIMEOFFSET column and you call ResultSet#getObject() with LocalDate/LocalTime/LocalDateTime as the class argument, the JDBC driver converts the value into the local time zone.
One could argue that the current behavior is correct, but IMO it is a bug because it does not align with what java.time.OffsetDateTime#toLocalDateTime() and
CAST(date_time_offset_column AS DATETIME2)
do, which is to ignore the offset.So this PR fixes the behavior for local types to ignore the offset.