Hi there,
DB2 uses the time format hh.mm.ss (
https://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.intro/src/tpc/db2z_datetimetimestamp.dita
). Currently this causes an exception DateTimeUtils.parseTimeNanos.
Is it possible to include the attached patch in H2 to support the hh.mm.ss
format as an alternative? Currently I do not see an option to limit this to
the DB2 compatibility mode.
best regards,
Niklas
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Index: src/test/org/h2/test/unit/TestDateTimeUtils.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/test/org/h2/test/unit/TestDateTimeUtils.java (revision )
+++ src/test/org/h2/test/unit/TestDateTimeUtils.java (revision )
@@ -0,0 +1,33 @@
+package org.h2.test.unit;
+
+import org.h2.test.TestBase;
+import org.h2.util.DateTimeUtils;
+
+/**
+ * Unit tests for the DateTimeUtils class
+ */
+public class TestDateTimeUtils extends TestBase {
+
+ /**
+ * Run just this test.
+ *
+ * @param a ignored
+ */
+ public static void main(String... a) throws Exception {
+ // System.setProperty("h2.storeLocalTime", "true");
+ TestBase.createCaller().init().test();
+ }
+
+ @Override
+ public void test() throws Exception {
+ testParseTimeNanos();
+ }
+
+ private void testParseTimeNanos() {
+ assertEquals(3723004000000L, DateTimeUtils.parseTimeNanos("01:02:03.004", 0, 12, true));
+ assertEquals(3723004000000L, DateTimeUtils.parseTimeNanos("01.02.03.004", 0, 12, true));
+
+ assertEquals(3723000000000L, DateTimeUtils.parseTimeNanos("01:02:03", 0, 8, true));
+ assertEquals(3723000000000L, DateTimeUtils.parseTimeNanos("01.02.03", 0, 8, true));
+ }
+}
Index: src/main/org/h2/util/DateTimeUtils.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/org/h2/util/DateTimeUtils.java (revision c46b8d770a22e8c77caff1713dcbd12f71f12f44)
+++ src/main/org/h2/util/DateTimeUtils.java (revision )
@@ -314,7 +314,7 @@
}
/**
- * Parse a time string. The format is: [-]hour:minute:second[.nanos]
+ * Parse a time string. The format is: [-]hour:minute:second[.nanos] or alternatively [-]hour.minute.second[.nanos].
*
* @param s the string to parse
* @param start the parse index start
@@ -332,7 +332,14 @@
int s2 = s.indexOf(':', s1 + 1);
int s3 = s.indexOf('.', s2 + 1);
if (s1 <= 0 || s2 <= s1) {
+ // if first try fails try to use IBM DB2 time format [-]hour.minute.second[.nanos]
+ s1 = s.indexOf('.', start);
+ s2 = s.indexOf('.', s1 + 1);
+ s3 = s.indexOf('.', s2 + 1);
+
+ if (s1 <= 0 || s2 <= s1) {
- throw new IllegalArgumentException(s);
+ throw new IllegalArgumentException(s);
+ }
}
boolean negative;
hour = Integer.parseInt(s.substring(start, s1));