From 5d9718216d85b6360214a12370a67970c6221574 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 15 Jan 2008 15:44:04 +0000 Subject: [PATCH] add some more date testing git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@215 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/DatabaseTest.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 091daf4..11b42d9 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -38,6 +38,8 @@ import java.io.PrintWriter; import java.math.BigDecimal; import java.nio.ByteBuffer; import java.sql.Types; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -771,7 +773,44 @@ public class DatabaseTest extends TestCase { db.close(); } - + + public void testWriteAndReadDate() throws Exception { + Database db = create(); + + List columns = new ArrayList(); + Column col = new Column(); + col.setName("name"); + col.setType(DataType.TEXT); + columns.add(col); + col = new Column(); + col.setName("date"); + col.setType(DataType.SHORT_DATE_TIME); + columns.add(col); + + db.createTable("test", columns); + Table table = db.getTable("test"); + + DateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); + List dates = + Arrays.asList( + df.parse("19801231 00:00:00"), + df.parse("19930513 14:43:27"), + null, + df.parse("20210102 02:37:00"), + new Date()); + + for(Date d : dates) { + table.addRow("row " + d, d); + } + + List foundDates = new ArrayList(); + for(Map row : table) { + foundDates.add((Date)row.get("date")); + } + + assertEquals(dates, foundDates); + } + static Object[] createTestRow(String col1Val) { return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d, 777.88f, (short) 999, new Date()}; -- 2.39.5