From 1d0672541e6151150e8fb26f73f48c8b9fcdd4c3 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 5 Apr 2006 11:44:28 +0000 Subject: [PATCH] Fix for 12 vs 24 hour times git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@391591 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/util/SystemTimeUtils.java | 6 +++--- .../apache/poi/hslf/record/TestComment2000.java | 14 ++++++++++++-- .../poi/hslf/record/TestComment2000Atom.java | 14 +++++++------- .../apache/poi/hslf/util/TestSystemTimeUtils.java | 14 +++++++------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java b/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java index f00630d33b..c41e7d0647 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java +++ b/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java @@ -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 0 - 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)); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java index 2c582104ca..c4fd8f83cc 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java @@ -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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java index 4340f30f9d..0c47e30b9a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000Atom.java @@ -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 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java b/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java index 0df71c6703..5382ed4dd9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java @@ -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