-
Notifications
You must be signed in to change notification settings - Fork 828
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 LocalDate.MAX, special case for postgresql time column. Use 24:00… #992
Conversation
…:00 as marker for MAX
|
||
sbuf.setLength(0); | ||
|
||
if (localTime == LocalTime.MAX) { |
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.
@davecramer
Would it be better to do LocalTime.MAX.equals(localTime)
here, instead of using the reference equality?
Otherwise there will be a difference in write behavior between a LocalTime that has a value of 23:59:59.999999999
and when using LocalTime.MAX
, even though they are value-equal.
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.
good point, thx
Codecov Report
@@ Coverage Diff @@
## master #992 +/- ##
============================================
+ Coverage 65.92% 65.94% +0.01%
- Complexity 3560 3568 +8
============================================
Files 166 167 +1
Lines 15244 15251 +7
Branches 2465 2469 +4
============================================
+ Hits 10050 10057 +7
- Misses 4023 4025 +2
+ Partials 1171 1169 -2 |
LocalTime localTime = (LocalTime)rs.getObject(1,LocalTime.class); | ||
|
||
|
||
Assert.assertTrue( localTime == LocalTime.MAX); |
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.
Please use assertEquals(a, b)
(avoid assertTrue(expression)
)
@@ -77,20 +77,19 @@ public void testLocalTimeMax() throws SQLException { | |||
pstmt.executeUpdate(); | |||
|
|||
ResultSet rs = con.createStatement().executeQuery("select tt from timetable order by id asc"); | |||
Assert.assertTrue(rs.next()); | |||
Assert.assertEquals(true, rs.next()); |
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 assertTrue here was fine.
|
||
Assert.assertTrue(rs.next()); | ||
Assert.assertEquals(true, rs.next()); |
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 assertTrue here was fine.
'infinity'::time does not work, so 00:00:00 and 24:00:00 are used. # select '24:00:01'::time; ERROR: date/time field value out of range: "24:00:01" LINE 1: select '24:00:01'::time; fixes pgjdbc#991 (cherry picked from commit f2d8ec5)
What is the need to represent LocalTime.MAX as |
@bokken My understanding was that this was the unfortunate reason: |
What is the "time" of There has always been possible differences in precision between java and postgresql. For example, |
I think it is the other way around. We need to deal with postgresql's MAX
time of 24:00:00
Dave Cramer
…On 29 December 2017 at 17:47, Brett Okken ***@***.***> wrote:
What is the "time" of 24:00:00 in postgresql supposed to represent? Is
this to handle leap seconds? Or is this truly supposed to represent the
"next" midnight?
There has always been possible differences in precision between java and
postgresql. For example, java.sql.Time has millisecond precision. So it
has always been possible to try and store 23:59:59.999, which postgresql
would truncate to 23:59:59. The fact that there is a constant for
LocalTime.MAX that cannot be exactly represented in postgresql does not
seem to mean a "sentinel" with different hours, minutes, and seconds should
be substituted.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#992 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAYz9hq79DI8lV-mUhkS9vjJOW_f7KoNks5tFWwNgaJpZM4P_yeF>
.
|
Do you know what 24:00:00 is supposed to represent? Assuming it is the "next" midnight, then my proposal is that LocalTime should represent that as 00:00:00 (LocalTime.MIDNIGHT) and java.sql.Time should represent it as 1970-01-02 00:00:00. This certainly is not perfect, and LocalTime is not symmetrical (i.e. no way to set 24:00:00 and cannot distinguish between 00:00:00 and 24:00:00 on read). However, this seems perhaps the least surprising behavior. I asked previously about a leap second, but I seem to recall that is usually represented as 23:59:60. |
No, I don't know what it is supposed to represent. Do you have a reason for
changing the semantics of it ?
Dave Cramer
…On 30 December 2017 at 08:19, Brett Okken ***@***.***> wrote:
Do you know what 24:00:00 is supposed to represent?
Assuming it is the "next" midnight, then my proposal is that LocalTime
should represent that as 00:00:00 (LocalTime.MIDNIGHT
<https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html#MIDNIGHT>)
and java.sql.Time should represent it as 1970-01-02 00:00:00.
This certainly is not perfect, and LocalTime is not symmetrical (i.e. no
way to set 24:00:00 and cannot distinguish between 00:00:00 and 24:00:00 on
read). However, this seems perhaps the least surprising behavior.
I asked previously about a leap second, but I seem to recall that is
usually represented as 23:59:60.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#992 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAYz9rkuI4sEU2bXVFw1o38-0FcPKH33ks5tFjhJgaJpZM4P_yeF>
.
|
It appears looking at the code that it represents the number of seconds in
a day
Dave Cramer
…On 30 December 2017 at 09:00, Dave Cramer ***@***.***> wrote:
No, I don't know what it is supposed to represent. Do you have a reason
for changing the semantics of it ?
Dave Cramer
On 30 December 2017 at 08:19, Brett Okken ***@***.***>
wrote:
> Do you know what 24:00:00 is supposed to represent?
>
> Assuming it is the "next" midnight, then my proposal is that LocalTime
> should represent that as 00:00:00 (LocalTime.MIDNIGHT
> <https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html#MIDNIGHT>)
> and java.sql.Time should represent it as 1970-01-02 00:00:00.
>
> This certainly is not perfect, and LocalTime is not symmetrical (i.e. no
> way to set 24:00:00 and cannot distinguish between 00:00:00 and 24:00:00 on
> read). However, this seems perhaps the least surprising behavior.
>
> I asked previously about a leap second, but I seem to recall that is
> usually represented as 23:59:60.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#992 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AAYz9rkuI4sEU2bXVFw1o38-0FcPKH33ks5tFjhJgaJpZM4P_yeF>
> .
>
|
I do not (necessarily) want to change the semantics, I want to clarify/understand the semantics. So it sounds like the time column represents 0-86,400,000,000 microseconds, and LocalTime represents 0-85,399,999,999,999 nano seconds. On inserts, I think it would be best to leave LocalTime.MAX as 23:59:99.999999. Currently, on inserts of java.sql.Time, there is also no way to set 24:00:00. That does not seem problematic, and I don't think that introducing support for LocalTime needs to change that. On reads, if |
I need to correct a mis-statement. I stated that 24:00:00 has historically been handled with java.sql.Time as 1970-01-02 00:00:00. That is not accurate. It has been handled as 1970-01-01 00:00:00. Which is to say, no distinction between 00:00:00 and 24:00:00. |
I've updated the tests to reflect historical behavior and to also include tests of the binary representation. Given the historical behavior of getTime treating 00:00:00 and 24:00:00 the same, I think it makes most sense for getObject(LocalTime.class) to do the same. |
I have now also included proposed code changes to address test failures. #1049 I did identify 3 assertions in in tests in TimezoneTest which appeared to be wrong. All 3 were testing time with timezone or timestamp with timezone columns and were asserting that a different value would result if the ResultSet were called with a specific different Calendar. Indeed it asserted that it was the same value when called with a number of different Calendars. |
…:00 as marker for MAX