commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1432175 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
Date Fri, 11 Jan 2013 17:27:46 GMT
Author: bodewig
Date: Fri Jan 11 17:27:46 2013
New Revision: 1432175

URL: http://svn.apache.org/viewvc?rev=1432175&view=rev
Log:
adjust test expectations to the difference in InfoZIP's and ZipEntry's interpretation of the
LFH time

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java?rev=1432175&r1=1432174&r2=1432175&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
Fri Jan 11 17:27:46 2013
@@ -102,8 +102,7 @@ public class X5455_ExtendedTimestampTest
                 ZipArchiveEntry zae = en.nextElement();
                 String name = zae.getName();
                 X5455_ExtendedTimestamp xf = (X5455_ExtendedTimestamp) zae.getExtraField(X5455);
-
-                Date z = zae.getLastModifiedDate();
+                Date z = adjustFromGMTToExpectedOffset(zae.getLastModifiedDate());
                 Date m = xf.getModifyJavaTime();
                 Date a = xf.getAccessJavaTime();
 
@@ -124,7 +123,7 @@ public class X5455_ExtendedTimestampTest
                         switch (year) {
                             case 2107:
                                 // Zip time is okay up to 2107.
-                                assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                assertEquals(year  + "-01-01/00:00:02 +0000", zipTime);
                                 // But the X5455 data has overflowed:
                                 assertEquals("1970-11-24/17:31:45 +0000", modTime);
                                 assertEquals("1970-11-24/17:31:47 +0000", accTime);
@@ -458,4 +457,21 @@ public class X5455_ExtendedTimestampTest
     }
 
     private static boolean isFlagSet(byte data, byte flag) { return (data & flag) ==
flag; }
+
+    /**
+     * InfoZIP seems to adjust the time stored inside the LFH and CD
+     * to GMT when writing ZIPs while java.util.zip.ZipEntry thinks it
+     * was in local time.
+     *
+     * The archive read in {@see #testSampleFile} has been created
+     * with GMT-8 so we need to adjust for the difference.
+     */
+    private static Date adjustFromGMTToExpectedOffset(Date from) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(from);
+        // we may even need to take DST into account for the southern hemisphere
+        cal.add(Calendar.MILLISECOND, cal.get(Calendar.ZONE_OFFSET));
+        cal.add(Calendar.HOUR, 8);
+        return cal.getTime();
+    }
 }



Mime
View raw message