提交 0e36eb37 authored 作者: Niklas Mehner's avatar Niklas Mehner

Merge branch 'master' of https://github.com/h2database/h2database

......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Support for DB2 time format, patch by Niklas Mehner
</li>
<li>Added support for Connection.setClientInfo() in compatibility modes for DB2, Postgresql, Oracle and MySQL.
</li>
<li>Issue #249: Clarify license declaration in Maven POM xml
......
......@@ -314,7 +314,7 @@ public class DateTimeUtils {
}
/**
* 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
......@@ -331,9 +331,16 @@ public class DateTimeUtils {
int s1 = s.indexOf(':', start);
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);
}
}
boolean negative;
hour = Integer.parseInt(s.substring(start, s1));
if (hour < 0) {
......
......@@ -170,6 +170,7 @@ import org.h2.test.unit.TestConnectionInfo;
import org.h2.test.unit.TestDataPage;
import org.h2.test.unit.TestDate;
import org.h2.test.unit.TestDateIso8601;
import org.h2.test.unit.TestDateTimeUtils;
import org.h2.test.unit.TestExit;
import org.h2.test.unit.TestFile;
import org.h2.test.unit.TestFileLock;
......@@ -871,6 +872,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
// serial
addTest(new TestDate());
addTest(new TestDateTimeUtils());
addTest(new TestCluster());
addTest(new TestConcurrent());
addTest(new TestFileLockSerialized());
......
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
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 {
testParseTimeNanosDB2Format();
}
private void testParseTimeNanosDB2Format() {
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));
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论