From d42cb3322d5478148f395d269e2bf52cbfe01549 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 30 Aug 2022 13:44:15 -0700 Subject: Use `JarEntry#setTimeLocal` This method was added in JDK 9, and allows setting jar entry times without going through a `long` of milliseconds. Both `setTime` and `setTimeLocal` implicitly use the default timezone. PiperOrigin-RevId: 471079483 --- java/com/google/turbine/main/Main.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/java/com/google/turbine/main/Main.java b/java/com/google/turbine/main/Main.java index da97bcd..34984a8 100644 --- a/java/com/google/turbine/main/Main.java +++ b/java/com/google/turbine/main/Main.java @@ -58,7 +58,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -433,16 +432,11 @@ public final class Main { } /** Normalize timestamps. */ - static final long DEFAULT_TIMESTAMP = - LocalDateTime.of(2010, 1, 1, 0, 0, 0) - .atZone(ZoneId.systemDefault()) - .toInstant() - .toEpochMilli(); + static final LocalDateTime DEFAULT_TIMESTAMP = LocalDateTime.of(2010, 1, 1, 0, 0, 0); private static void addEntry(JarOutputStream jos, String name, byte[] bytes) throws IOException { JarEntry je = new JarEntry(name); - // TODO(cushon): switch to setLocalTime after we migrate to JDK 9 - je.setTime(DEFAULT_TIMESTAMP); + je.setTimeLocal(DEFAULT_TIMESTAMP); je.setMethod(ZipEntry.STORED); je.setSize(bytes.length); je.setCrc(Hashing.crc32().hashBytes(bytes).padToLong()); -- cgit v1.2.3