// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.java.turbine.javac;

import java.io.IOException;
import java.util.GregorianCalendar;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * Static utility methods for working with ZipOutputStream.
 */
public abstract class ZipUtil {

  /** The earliest date representable in a zip file, the DOS epoch. */
  private static final long DOS_EPOCH =
      new GregorianCalendar(1980, 0, 1, 0, 0, 0).getTimeInMillis();

  /**
   * This is a helper method for adding an uncompressed entry to a
   * ZipOutputStream.  The entry timestamp is also set to a fixed value.
   *
   * @param name filename to use within the zip file
   * @param content file contents
   * @param zip the ZipOutputStream to which this entry will be appended
   */
  public static void storeEntry(String name, byte[] content, ZipOutputStream zip)
      throws IOException {
    ZipEntry entry = new ZipEntry(name);
    entry.setMethod(ZipEntry.STORED);
    entry.setTime(DOS_EPOCH);
    entry.setSize(content.length);
    CRC32 crc32 = new CRC32();
    crc32.update(content);
    entry.setCrc(crc32.getValue());
    zip.putNextEntry(entry);
    zip.write(content);
    zip.closeEntry();
  }
}

@@ -708,30 +708,51 @@
 ava.
-u
 ti
-l.GregorianCalendar
+me.LocalDateTime;%0Aimport java.time.ZoneId
 ;%0Aim
@@ -958,148 +958,103 @@
 /** 
-The earliest date representable in a zip file, the DOS epoch. */%0A  private static final long DOS_EPOCH =%0A      new GregorianCalendar(1980, 0
+Normalize timestamps. */%0A  static final long DEFAULT_TIMESTAMP =%0A      LocalDateTime.of(2010, 1
 , 1,
@@ -1066,24 +1066,97 @@
 , 0)
-.getTimeIn
+%0A          .atZone(ZoneId.systemDefault())%0A          .toInstant()%0A          .toEpoch
 Milli
-s
 ();%0A
@@ -1661,16 +1661,86 @@
 TORED);%0A
+    // TODO(cushon): switch to setLocalTime after we migrate to JDK 9%0A
     entr
@@ -1754,16 +1754,24 @@
 me(D
-OS_EPOCH
+EFAULT_TIMESTAMP
 );%0A 

Use a different date time when normalizing zip entries