From 519c88d4da6b4e9df4c8080aab1d03b9ab748629 Mon Sep 17 00:00:00 2001 From: Elijah Zupancic Date: Tue, 14 Dec 2021 09:42:39 -0800 Subject: [PATCH] test: revert change to UTC formatting in unit tests This change formats iso timestamps using JVM date formatting in order to compare with the output from log4j date formatting. --- src/test/java/log4j/layout/bunyan/LogOutputTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/log4j/layout/bunyan/LogOutputTest.java b/src/test/java/log4j/layout/bunyan/LogOutputTest.java index f6f8a23..c2933e3 100644 --- a/src/test/java/log4j/layout/bunyan/LogOutputTest.java +++ b/src/test/java/log4j/layout/bunyan/LogOutputTest.java @@ -23,6 +23,9 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -255,8 +258,8 @@ void validateEvent(final LogEvent event, final String json) throws IOException { } static String formatAsUTCTimestamp(final long epochMillis) { - StringBuilder buffer = new StringBuilder(); - DatePatternConverterFactory.instance().format(epochMillis, buffer); - return buffer.toString(); + final Instant instant = Instant.ofEpochMilli(epochMillis); + return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC) + .format(DateTimeFormatter.ISO_INSTANT); } }