aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/com/healthmarketscience/jackcess
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-12-15 06:13:06 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-12-15 06:13:06 +0000
commit843a44dfe074a2b587ff4aacbd4089ab22e6f087 (patch)
tree6e60f2cb73c9e113bf3158249f95b32d1b7caad3 /src/test/java/com/healthmarketscience/jackcess
parent99af2bc3a62fe0e710bb386365770439bc2984c3 (diff)
downloadjackcess-843a44dfe074a2b587ff4aacbd4089ab22e6f087.tar.gz
jackcess-843a44dfe074a2b587ff4aacbd4089ab22e6f087.zip
switch expression engine to LocalDateTime
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1238 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience/jackcess')
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java4
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java18
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java7
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java33
4 files changed, 35 insertions, 27 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java
index 384386e..bb26719 100644
--- a/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java
@@ -294,8 +294,8 @@ public class PropertyExpressionTest extends TestCase
public static void testCustomEvalConfig() throws Exception
{
- TemporalConfig tempConf = new TemporalConfig("yyyy/M/d", "M/d",
- "yyyy-MMM-d",
+ TemporalConfig tempConf = new TemporalConfig("[uuuu/]M/d",
+ "uuuu-MMM-d",
"hh.mm.ss a",
"HH.mm.ss", '/', '.',
Locale.US);
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java
index 561f1e8..104b266 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java
@@ -16,6 +16,9 @@ limitations under the License.
package com.healthmarketscience.jackcess.impl;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -53,7 +56,7 @@ public class DatabaseReadWriteTest extends TestCase
db.close();
}
}
-
+
public void testWriteAndReadInMem() throws Exception {
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
@@ -61,7 +64,7 @@ public class DatabaseReadWriteTest extends TestCase
db.close();
}
}
-
+
private static void doTestWriteAndRead(Database db) throws Exception {
createTestTable(db);
Object[] row = createTestRow();
@@ -117,7 +120,7 @@ public class DatabaseReadWriteTest extends TestCase
}
}
- public void testUpdateRow() throws Exception
+ public void testUpdateRow() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
@@ -250,11 +253,18 @@ public class DatabaseReadWriteTest extends TestCase
final long timeRange = 100000000L;
final long timeStep = 37L;
- for(long time = testTime - timeRange; time < testTime + timeRange;
+ for(long time = testTime - timeRange; time < testTime + timeRange;
time += timeStep) {
double accTime = ColumnImpl.toLocalDateDouble(time);
long newTime = ColumnImpl.fromLocalDateDouble(accTime);
assertEquals(time, newTime);
+
+ Instant inst = Instant.ofEpochMilli(time);
+ LocalDateTime ldt = LocalDateTime.ofInstant(inst, ZoneOffset.UTC);
+
+ accTime = ColumnImpl.toDateDouble(ldt);
+ LocalDateTime newLdt = ColumnImpl.ldtFromLocalDateDouble(accTime);
+ assertEquals(ldt, newLdt);
}
}
}
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
index b50f2de..895bbed 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
@@ -17,6 +17,7 @@ limitations under the License.
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
@@ -78,9 +79,9 @@ public class DefaultFunctionsTest extends TestCase
eval("=CSng(\"57.12345\")"));
assertEval("9786", "=CStr(9786)");
assertEval("-42", "=CStr(-42)");
- assertEval(new Date(1041483600000L), "=CDate('01/02/2003')");
- assertEval(new Date(1041508800000L), "=CDate('01/02/2003 7:00:00 AM')");
- assertEval(new Date(-1948781520000L), "=CDate(3013.45)");
+ assertEval(LocalDateTime.of(2003,1,2,0,0), "=CDate('01/02/2003')");
+ assertEval(LocalDateTime.of(2003,1,2,7,0), "=CDate('01/02/2003 7:00:00 AM')");
+ assertEval(LocalDateTime.of(1908,3,31,10,48), "=CDate(3013.45)");
assertEval(-1, "=IsNull(Null)");
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java
index c67dfe7..67ad20b 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java
@@ -20,14 +20,13 @@ import java.io.BufferedReader;
import java.io.FileReader;
import java.math.BigDecimal;
import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import javax.script.Bindings;
import javax.script.SimpleBindings;
import com.healthmarketscience.jackcess.DataType;
-import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.TestUtil;
import com.healthmarketscience.jackcess.expr.EvalContext;
import com.healthmarketscience.jackcess.expr.Expression;
@@ -38,7 +37,6 @@ import com.healthmarketscience.jackcess.expr.ParseException;
import com.healthmarketscience.jackcess.expr.TemporalConfig;
import com.healthmarketscience.jackcess.expr.Value;
import com.healthmarketscience.jackcess.impl.BaseEvalContext;
-import com.healthmarketscience.jackcess.impl.expr.NumberFormatter;
import junit.framework.TestCase;
/**
@@ -318,11 +316,11 @@ public class ExpressionatorTest extends TestCase
public void testDateArith() throws Exception
{
- assertEquals(new Date(1041508800000L), eval("=#01/02/2003# + #7:00:00 AM#"));
- assertEquals(new Date(1041458400000L), eval("=#01/02/2003# - #7:00:00 AM#"));
- assertEquals(new Date(1044680400000L), eval("=#01/02/2003# + '37'"));
- assertEquals(new Date(1044680400000L), eval("='37' + #01/02/2003#"));
- assertEquals(new Date(1041508800000L), eval("=#01/02/2003 7:00:00 AM#"));
+ assertEquals(LocalDateTime.of(2003,1,2,7,0), eval("=#01/02/2003# + #7:00:00 AM#"));
+ assertEquals(LocalDateTime.of(2003,1,1,17,0), eval("=#01/02/2003# - #7:00:00 AM#"));
+ assertEquals(LocalDateTime.of(2003,2,8,0,0), eval("=#01/02/2003# + '37'"));
+ assertEquals(LocalDateTime.of(2003,2,8,0,0), eval("='37' + #01/02/2003#"));
+ assertEquals(LocalDateTime.of(2003,1,2,7,0), eval("=#01/02/2003 7:00:00 AM#"));
assertEquals("2/8/2003", eval("=CStr(#01/02/2003# + '37')"));
assertEquals("9:24:00 AM", eval("=CStr(#7:00:00 AM# + 0.1)"));
@@ -404,7 +402,7 @@ public class ExpressionatorTest extends TestCase
assertEquals("foo37", eval("=\"foo\" + (12 + 25)"));
assertEquals("25foo12", eval("=\"25foo\" + 12"));
- assertEquals(new Date(1485579600000L), eval("=#1/1/2017# + 27"));
+ assertEquals(LocalDateTime.of(2017,1,28,0,0), eval("=#1/1/2017# + 27"));
assertEquals(128208, eval("=#1/1/2017# * 3"));
}
@@ -590,15 +588,14 @@ public class ExpressionatorTest extends TestCase
return TemporalConfig.US_TEMPORAL_CONFIG;
}
- public SimpleDateFormat createDateFormat(String formatStr) {
- SimpleDateFormat sdf = DatabaseBuilder.createDateFormat(formatStr);
- sdf.setTimeZone(TestUtil.TEST_TZ);
- return sdf;
+ public DateTimeFormatter createDateFormatter(String formatStr) {
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern(
+ formatStr, TemporalConfig.US_TEMPORAL_CONFIG.getLocale());
+ return dtf;
}
- public Calendar getCalendar() {
- return createDateFormat(getTemporalConfig().getDefaultDateTimeFormat())
- .getCalendar();
+ public ZoneId getZoneId() {
+ return TestUtil.TEST_TZ.toZoneId();
}
public NumericConfig getNumericConfig() {