Hi,
I was scanning the ant source, and saw some deprecated calls (Date.getDate() etc). Not sure if it's worthwhile, but I made a quick change to use the newer Calendar class. I also wrote a quick unit test. Both source and unit test are included in the patch (sorry Eclipse CVS integration is still a little new to me).
Again sorry if completely pointless.
Kev
Index: ZipOutputStream.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/zip/ZipOutputStream.java,v
retrieving revision 1.24
diff -u -r1.24 ZipOutputStream.java
--- ZipOutputStream.java 18 May 2004 08:14:48 -0000 1.24
+++ ZipOutputStream.java 3 Nov 2004 06:01:53 -0000
@@ -30,6 +30,7 @@
import java.util.zip.CRC32;
import java.util.zip.Deflater;
import java.util.zip.ZipException;
+import java.util.Calendar;
/**
* Reimplementation of [EMAIL PROTECTED] java.util.zip.ZipOutputStream
@@ -769,17 +770,19 @@
* @since 1.1
*/
protected static ZipLong toDosTime(Date time) {
- int year = time.getYear() + 1900;
- int month = time.getMonth() + 1;
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(time);
+ int year = cal.get(Calendar.YEAR);
+ int month = cal.get(Calendar.MONTH) + 1;
if (year < 1980) {
return DOS_TIME_MIN;
}
long value = ((year - 1980) << 25)
| (month << 21)
- | (time.getDate() << 16)
- | (time.getHours() << 11)
- | (time.getMinutes() << 5)
- | (time.getSeconds() >> 1);
+ | (cal.get(Calendar.DAY_OF_MONTH) << 16)
+ | (cal.get(Calendar.HOUR_OF_DAY) << 11)
+ | (cal.get(Calendar.MINUTE) << 5)
+ | (cal.get(Calendar.SECOND) >> 1);
byte[] result = new byte[4];
result[0] = (byte) ((value & 0xFF));
Index: ZipOutputStreamTest.java
===================================================================
RCS file: ZipOutputStreamTest.java
diff -N ZipOutputStreamTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ZipOutputStreamTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,65 @@
+
+package org.apache.tools.zip;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.util.Date;
+
+
+
+public class ZipOutputStreamTest extends TestCase {
+
+ private Date time;
+ private ZipLong zl;
+
+ /**
+ * Constructor
+ */
+ public ZipOutputStreamTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new ZipOutputStreamTest("testZipLong"));
+ return suite;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ time = new Date();
+ byte[] result = new byte[4];
+ int year = time.getYear() + 1900;
+ int month = time.getMonth() + 1;
+ long value = ((year - 1980) << 25)
+ | (month << 21)
+ | (time.getDate() << 16)
+ | (time.getHours() << 11)
+ | (time.getMinutes() << 5)
+ | (time.getSeconds() >> 1);
+
+ result[0] = (byte) ((value & 0xFF));
+ result[1] = (byte) ((value & 0xFF00) >> 8);
+ result[2] = (byte) ((value & 0xFF0000) >> 16);
+ result[3] = (byte) ((value & 0xFF000000L) >> 24);
+ zl = new ZipLong(result);
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testZipLong() {
+ try {
+ ZipLong test = ZipOutputStream.toDosTime(time);
+ assertEquals(test.getValue(), zl.getValue());
+ } catch (Exception e) {
+ fail();
+ e.printStackTrace();
+ }
+
+ }
+
+}--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
