Hello there!
I have stumbled upon the jar tool always printing nominally the same date and
time for a JarEntry, regardless of the timezone set. Confused by this, I dug
into the code only to find out that the zip file format does neither store
timezone information nor timestamps in UTC. This basically means that timestamps
in jar/zip files are or can be assumed to always be in the local timezone, hence
there is no conceivable fix for this problem, except for altering the zip file
format specification. However, timestamps are printed in the en_US locale
currently. This locale is /almost/ as arbitrary as every other. So, this patch
makes the jar tool print timestamps in the default locale date and time format.
If anybody is bothered by this change they can still explicitly set the
user.language property or the system's locale to en_US.
If anybody /really/ wants to parse jar tool's timestamps output they should
probably be relying on ISO formatted timestamps. I can add this functionality as
a flag.
Anyways, please review this patch.
Regards,
Jacob
diff -r 4e3d1c1a2ba7 src/share/classes/sun/tools/jar/Main.java
--- a/src/share/classes/sun/tools/jar/Main.java
+++ b/src/share/classes/sun/tools/jar/Main.java
@@ -33,6 +33,7 @@
import java.util.jar.*;
import java.util.jar.Pack200.*;
import java.util.jar.Manifest;
+import java.text.DateFormat;
import java.text.MessageFormat;
import sun.misc.JarIndex;
import static sun.misc.JarIndex.INDEX_NAME;
@@ -1181,9 +1182,14 @@
for (int i = 6 - s.length(); i > 0; --i) {
sb.append(' ');
}
- sb.append(s).append(' ').append(new Date(e.getTime()).toString());
- sb.append(' ').append(e.getName());
- output(sb.toString());
+ output(sb.append(s).
+ append(' ').
+ append(
+ DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.LONG).
+ format(new Date(e.getTime()))).
+ append(' ').
+ append(e.getName()).
+ toString());
} else {
output(e.getName());
}