java.time.Instant.toString() nanosecond bug
Arne Ploese
aploese at gmx.de
Tue Jan 17 20:07:11 UTC 2017
Hi,
I'm runnig
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-3-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
and I encounter the following bug.
TestCase:
@Test
public void testNanos() {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.nnnnnnX");
Instant instant = Instant.ofEpochSecond(0, 123400);
assertEquals(0, instant.getEpochSecond());
assertEquals(123400, instant.getNano());
assertEquals("1970-01-01T00:00:00.123400Z",
formatter.format(ZonedDateTime.ofInstant(instant, ZoneId.of("Z"))));
assertEquals("1970-01-01T00:00:00.123400Z",
instant.toString());
}
The test fails on the last assertEquals with:
org.junit.ComparisonFailure: expected:<1970-01-01T00:00:00.[]123400Z>
but was:<1970-01-01T00:00:00.[000]123400Z>
the nanos getting three leading zeros.
Arne Plöse
More information about the core-libs-dev
mailing list