-
Bug
-
Resolution: Fixed
-
P3
-
18
-
b22
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8308140 | 20u-cpu | Roger Riggs | P3 | Resolved | Fixed | master |
JDK-8308008 | 20.0.2 | Roger Riggs | P3 | Resolved | Fixed | b05 |
Consider the following code:
var t1 = Instant.parse("2023-05-03T10:00:00.000999Z");
var t2 = Instant.parse("2023-05-03T10:00:01.000Z");
var t3 = Instant.parse("2023-05-03T10:00:01.001Z");
System.out.println(MILLIS.between(t1, t2));
System.out.println(MILLIS.between(t1, t3));
This prints:
1000
1000
Given that t3 is exactly one millisecond later than t2, it does not seem reasonable that they can both be 1000 milliseconds later than t1.
The JavaDoc for between() states "The calculation returns a whole number, representing the number of complete units between the two temporals."
Assuming I have understood this correctly, I think MILLIS.between(t1, t3) is correct but MILLIS.between(t1, t2) should return 999.
Reported to core-libs-dev mai:
https://mail.openjdk.org/pipermail/core-libs-dev/2023-May/105229.html
var t1 = Instant.parse("2023-05-03T10:00:00.000999Z");
var t2 = Instant.parse("2023-05-03T10:00:01.000Z");
var t3 = Instant.parse("2023-05-03T10:00:01.001Z");
System.out.println(MILLIS.between(t1, t2));
System.out.println(MILLIS.between(t1, t3));
This prints:
1000
1000
Given that t3 is exactly one millisecond later than t2, it does not seem reasonable that they can both be 1000 milliseconds later than t1.
The JavaDoc for between() states "The calculation returns a whole number, representing the number of complete units between the two temporals."
Assuming I have understood this correctly, I think MILLIS.between(t1, t3) is correct but MILLIS.between(t1, t2) should return 999.
Reported to core-libs-dev mai:
https://mail.openjdk.org/pipermail/core-libs-dev/2023-May/105229.html
- backported by
-
JDK-8308008 java.time.Instant calculation bug in until and between methods
- Resolved
-
JDK-8308140 java.time.Instant calculation bug in until and between methods
- Resolved
- csr for
-
JDK-8307578 Error computing the amount of milli and micro seconds between java.time.Instants
- Closed
- relates to
-
JDK-8273369 Computing micros between two instants unexpectedly overflows for some cases
- Closed
(2 links to)