Details
-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u131
-
generic
-
generic
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux energy80.workstations.ems 4.10.17-200.fc25.x86_64 #1 SMP Mon May 22 18:12:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
There is not sub-category for the "java.time" package, so I am forced to submit this bug under a wrong sub-category. Sorry for that.
java.Instant.truncatedTo(ChronoUnit) seems to produce wrong results if the instant the method is called on is before Instant.EPOCH. I expect this method to always round down, but in this case it rounds up. There is nothing in the JavaDoc that suggests this behaviour.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute this main-method:
public static void main(String[] args) {
System.out.println(Instant.ofEpochMilli(-1).truncatedTo(ChronoUnit.SECONDS));
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected output of the main method:
1969-12-31T23:59:59Z
ACTUAL -
Actual output of the main method:
1970-01-01T00:00:00Z
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.junit.Assert;
public class TruncatingInstantTest {
public static void main(String[] args) {
Instant expectedResult = Instant.EPOCH.minusSeconds(1);
Instant truncated = Instant.ofEpochMilli(-1).truncatedTo(ChronoUnit.SECONDS);
Assert.assertEquals(expectedResult, truncated);
}
}
---------- END SOURCE ----------
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux energy80.workstations.ems 4.10.17-200.fc25.x86_64 #1 SMP Mon May 22 18:12:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
There is not sub-category for the "java.time" package, so I am forced to submit this bug under a wrong sub-category. Sorry for that.
java.Instant.truncatedTo(ChronoUnit) seems to produce wrong results if the instant the method is called on is before Instant.EPOCH. I expect this method to always round down, but in this case it rounds up. There is nothing in the JavaDoc that suggests this behaviour.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute this main-method:
public static void main(String[] args) {
System.out.println(Instant.ofEpochMilli(-1).truncatedTo(ChronoUnit.SECONDS));
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected output of the main method:
1969-12-31T23:59:59Z
ACTUAL -
Actual output of the main method:
1970-01-01T00:00:00Z
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.junit.Assert;
public class TruncatingInstantTest {
public static void main(String[] args) {
Instant expectedResult = Instant.EPOCH.minusSeconds(1);
Instant truncated = Instant.ofEpochMilli(-1).truncatedTo(ChronoUnit.SECONDS);
Assert.assertEquals(expectedResult, truncated);
}
}
---------- END SOURCE ----------
Attachments
Issue Links
- duplicates
-
JDK-8134928 java.time.Instant.truncatedTo(TemporalUnit unit) is truncating up if the year < 1970
- Resolved