From: James Ahlborn Date: Fri, 28 Dec 2018 04:40:07 +0000 (+0000) Subject: more ldt tests X-Git-Tag: jackcess-3.0.0~7^2~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8dae0688daad08a789e9357c8245c4a20ef2b212;p=jackcess.git more ldt tests git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1254 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java b/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java index e17bbfb..0760b95 100644 --- a/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java @@ -26,6 +26,7 @@ import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAccessor; import java.util.ArrayList; @@ -225,4 +226,65 @@ public class LocalDateTimeTest extends TestCase } } + public void testWriteAndReadTemporals() throws Exception { + ZoneId zoneId = ZoneId.of("America/New_York"); + for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + Database db = createMem(fileFormat); + db.setZoneId(zoneId); + db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); + + Table table = new TableBuilder("test") + .addColumn(new ColumnBuilder("name", DataType.TEXT)) + .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + .toTable(db); + + // since jackcess does not really store millis, shave them off before + // storing the current date/time + long curTimeNoMillis = (System.currentTimeMillis() / 1000L); + curTimeNoMillis *= 1000L; + + DateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); + List tmpDates = + new ArrayList( + Arrays.asList( + df.parse("19801231 00:00:00"), + df.parse("19930513 14:43:27"), + df.parse("20210102 02:37:00"), + new Date(curTimeNoMillis))); + + List objs = new ArrayList(); + List expected = new ArrayList(); + for(Date d : tmpDates) { + Instant inst = Instant.ofEpochMilli(d.getTime()); + objs.add(inst); + ZonedDateTime zdt = inst.atZone(zoneId); + objs.add(zdt); + LocalDateTime ldt = zdt.toLocalDateTime(); + objs.add(ldt); + + for(int i = 0; i < 3; ++i) { + expected.add(ldt); + } + } + + ((DatabaseImpl)db).getPageChannel().startWrite(); + try { + for(Object o : objs) { + table.addRow("row " + o, o); + } + } finally { + ((DatabaseImpl)db).getPageChannel().finishWrite(); + } + + List foundDates = new ArrayList(); + for(Row row : table) { + foundDates.add(row.getLocalDateTime("date")); + } + + assertEquals(expected, foundDates); + + db.close(); + } + } + }