]> source.dussan.org Git - poi.git/commitdiff
Fix for 12 vs 24 hour times
authorNick Burch <nick@apache.org>
Wed, 5 Apr 2006 11:44:28 +0000 (11:44 +0000)
committerNick Burch <nick@apache.org>
Wed, 5 Apr 2006 11:44:28 +0000 (11:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@391591 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java
src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java
src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java
src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java

index f00630d33b94f6f26d53c4a493e5766f3d579cad..c41e7d06476b59594d1b2cb3e0ad0ff5f0ede4a3 100644 (file)
@@ -50,10 +50,10 @@ public class SystemTimeUtils {
         
         cal.set(Calendar.YEAR,         LittleEndian.getShort(data,offset));
         cal.set(Calendar.MONTH,        LittleEndian.getShort(data,offset+2)-1);
-        // Not actually needed - can be found from day of month 
+        // Not actually needed - can be found from day of month 
         //cal.set(Calendar.DAY_OF_WEEK,  LittleEndian.getShort(data,offset+4)+1);
         cal.set(Calendar.DAY_OF_MONTH, LittleEndian.getShort(data,offset+6));
-        cal.set(Calendar.HOUR,         LittleEndian.getShort(data,offset+8));
+        cal.set(Calendar.HOUR_OF_DAY,  LittleEndian.getShort(data,offset+8));
         cal.set(Calendar.MINUTE,       LittleEndian.getShort(data,offset+10));
         cal.set(Calendar.SECOND,       LittleEndian.getShort(data,offset+12));
         cal.set(Calendar.MILLISECOND,  LittleEndian.getShort(data,offset+14));
@@ -80,7 +80,7 @@ public class SystemTimeUtils {
         LittleEndian.putShort(dest, offset + 2, (short)(cal.get(Calendar.MONTH) + 1));
         LittleEndian.putShort(dest, offset + 4, (short)(cal.get(Calendar.DAY_OF_WEEK)-1));
         LittleEndian.putShort(dest, offset + 6, (short) cal.get(Calendar.DAY_OF_MONTH));
-        LittleEndian.putShort(dest, offset + 8, (short) cal.get(Calendar.HOUR));
+        LittleEndian.putShort(dest, offset + 8, (short) cal.get(Calendar.HOUR_OF_DAY));
         LittleEndian.putShort(dest, offset + 10,(short) cal.get(Calendar.MINUTE));
         LittleEndian.putShort(dest, offset + 12,(short) cal.get(Calendar.SECOND));
         LittleEndian.putShort(dest, offset + 14,(short) cal.get(Calendar.MILLISECOND));
index 2c582104caa5af535bc4597274593d4babdf32cb..c4fd8f83cc997359b86ac5c5114b002f5a0ebbcc 100644 (file)
@@ -79,7 +79,7 @@ public class TestComment2000 extends TestCase {
                0x48, 00,
                00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
                01, 00, 00, 00, 0xD6-256, 0x07, 01, 00, 
-               02, 00, 0x18, 00, 0x0A, 00, 0x19, 00, 03,
+               02, 00, 0x18, 00, 0x16, 00, 0x19, 00, 03,
                00, 0xD5-256, 02, 0x0A, 00, 00, 00, 
                0x0A, 00, 00, 00
                };
@@ -106,9 +106,19 @@ public class TestComment2000 extends TestCase {
                assertEquals(1, c2a.getNumber());
                assertEquals(0x92, c2a.getXOffset());
                assertEquals(0x92, c2a.getYOffset());
-               Date exp_a = sdf.parse("2006-01-24 22:26:15.205");
+               Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
                assertEquals(exp_a, c2a.getDate());
        }
+       public void testCommentAtomB() throws Exception {
+               Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
+               Comment2000Atom c2b = cb.getComment2000Atom();
+               
+               assertEquals(1, c2b.getNumber());
+               assertEquals(0x0a, c2b.getXOffset());
+               assertEquals(0x0a, c2b.getYOffset());
+               Date exp_b = sdf.parse("2006-01-24 22:25:03.725");
+               assertEquals(exp_b, c2b.getDate());
+       }
 
        public void testWrite() throws Exception {
                Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
index 4340f30f9db9a7a059373fea384a9c13ad80c610..0c47e30b9a5e5500f4717708fcbbaeeb6830f812 100644 (file)
@@ -42,7 +42,7 @@ public class TestComment2000Atom extends TestCase {
        private byte[] data_b = new byte[] { 
                00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
                05, 00, 00, 00, 0xD6-256, 0x07, 01, 00, 
-               02, 00, 0x18, 00, 0x0A, 00, 0x19, 00, 03,
+               02, 00, 0x18, 00, 0x15, 00, 0x19, 00, 03,
                00, 0xD5-256, 02, 0x0A, 00, 00, 00, 
                0x0E, 00, 00, 00
                };
@@ -58,10 +58,10 @@ public class TestComment2000Atom extends TestCase {
                Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
                Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
 
-       // A is 2006-01-24 (2nd day of week) 22:26:15.205
-               Date exp_a = sdf.parse("2006-01-24 22:26:15.205");
-               // B is 2006-01-24 (2nd day of week) 22:25:03.725
-               Date exp_b = sdf.parse("2006-01-24 22:25:03.725");
+       // A is 2006-01-24 (2nd day of week) 20:26:15.205
+               Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
+               // B is 2006-01-24 (2nd day of week) 21:25:03.725
+               Date exp_b = sdf.parse("2006-01-24 21:25:03.725");
                
                assertEquals(exp_a, ca.getDate());
                assertEquals(exp_b, cb.getDate());
@@ -112,7 +112,7 @@ public class TestComment2000Atom extends TestCase {
        a.setYOffset(0x92);
        
        // Set the date
-               Date date_a = sdf.parse("2006-01-24 22:26:15.205");
+               Date date_a = sdf.parse("2006-01-24 10:26:15.205");
                a.setDate(date_a);
                
                // Check it's now the same as a
@@ -134,7 +134,7 @@ public class TestComment2000Atom extends TestCase {
                ca.setNumber(5);
                
                // Change the date
-               Date new_date = sdf.parse("2006-01-24 22:25:03.725");
+               Date new_date = sdf.parse("2006-01-24 21:25:03.725");
                ca.setDate(new_date);
                
                // Change the x and y
index 0df71c67037326fbec7bf7831884155c244c2a2e..5382ed4dd99ddace300640d89f27c7def0df0da8 100644 (file)
@@ -40,7 +40,7 @@ public class TestSystemTimeUtils extends TestCase {
        private byte[] data_b = new byte[] {
                00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
                01, 00, 00, 00, 0xD6-256, 0x07, 01, 00, 
-               02, 00, 0x18, 00, 0x0A, 00, 0x19, 00, 03,
+               02, 00, 0x18, 00, 0x15, 00, 0x19, 00, 03,
                00, 0xD5-256, 02, 0x0A, 00, 00, 00, 
                0x0A, 00, 00, 00
        };
@@ -50,8 +50,8 @@ public class TestSystemTimeUtils extends TestCase {
        public void testGetDateA() throws Exception {
                Date date = SystemTimeUtils.getDate(data_a);
                
-               // Is 2006-01-24 (2nd day of week) 22:26:15.205
-               Date exp = sdf.parse("2006-01-24 22:26:15.205");
+               // Is 2006-01-24 (2nd day of week) 10:26:15.205
+               Date exp = sdf.parse("2006-01-24 10:26:15.205");
                assertEquals(exp.getTime(), date.getTime());
                assertEquals(exp, date);
        }
@@ -59,15 +59,15 @@ public class TestSystemTimeUtils extends TestCase {
        public void testGetDateB() throws Exception {
                Date date = SystemTimeUtils.getDate(data_b, 8+4);
                
-               // Is 2006-01-24 (2nd day of week) 22:25:03.725
-               Date exp = sdf.parse("2006-01-24 22:25:03.725");
+               // Is 2006-01-24 (2nd day of week) 21:25:03.725
+               Date exp = sdf.parse("2006-01-24 21:25:03.725");
                assertEquals(exp.getTime(), date.getTime());
                assertEquals(exp, date);
        }
        
        public void testWriteDateA() throws Exception {
                byte[] out_a = new byte[data_a.length];
-               Date date = sdf.parse("2006-01-24 22:26:15.205");
+               Date date = sdf.parse("2006-01-24 10:26:15.205");
                SystemTimeUtils.storeDate(date, out_a);
                
                for(int i=0; i<out_a.length; i++) {
@@ -81,7 +81,7 @@ public class TestSystemTimeUtils extends TestCase {
                System.arraycopy(data_b, 0, out_b, 0, 12);
                System.arraycopy(data_b, 12+16, out_b, 12+16, data_b.length-12-16);
                
-               Date date = sdf.parse("2006-01-24 22:25:03.725");
+               Date date = sdf.parse("2006-01-24 21:25:03.725");
                SystemTimeUtils.storeDate(date, out_b, 12);
                
                for(int i=0; i<out_b.length; i++) {