diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2018-12-28 04:40:07 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2018-12-28 04:40:07 +0000 |
commit | 8dae0688daad08a789e9357c8245c4a20ef2b212 (patch) | |
tree | 6a10f5f113ff3c8ecce8c575699e9a5479f555e0 | |
parent | 0f568a46209da6557cfeab5f351bc6ee432eb3ea (diff) | |
download | jackcess-8dae0688daad08a789e9357c8245c4a20ef2b212.tar.gz jackcess-8dae0688daad08a789e9357c8245c4a20ef2b212.zip |
more ldt tests
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1254 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java | 62 |
1 files changed, 62 insertions, 0 deletions
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<Date> tmpDates = + new ArrayList<Date>( + Arrays.asList( + df.parse("19801231 00:00:00"), + df.parse("19930513 14:43:27"), + df.parse("20210102 02:37:00"), + new Date(curTimeNoMillis))); + + List<Object> objs = new ArrayList<Object>(); + List<LocalDateTime> expected = new ArrayList<LocalDateTime>(); + 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<LocalDateTime> foundDates = new ArrayList<LocalDateTime>(); + for(Row row : table) { + foundDates.add(row.getLocalDateTime("date")); + } + + assertEquals(expected, foundDates); + + db.close(); + } + } + } |