Unverified 提交 ee756ecb authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #895 from katzyn/datetime

Parse more variants of timestamps with time zones
......@@ -9,7 +9,7 @@ import java.io.Serializable;
import org.h2.util.DateTimeUtils;
/**
* How we expose "TIMESTAMP WITH TIMEZONE" in our ResultSets.
* How we expose "TIMESTAMP WITH TIME ZONE" in our ResultSets.
*/
public class TimestampWithTimeZone implements Serializable, Cloneable {
......
......@@ -4342,16 +4342,9 @@ public class Parser {
}
} else if (readIf("TIMESTAMP")) {
if (readIf("WITH")) {
// originally we used TIMEZONE, which turns out not to be
// standards-compliant, but lets keep backwards compatibility
if (readIf("TIMEZONE")) {
read("TIMEZONE");
original += " WITH TIMEZONE";
} else {
read("TIME");
read("ZONE");
original += " WITH TIME ZONE";
}
} else if (readIf("WITHOUT")) {
read("TIME");
read("ZONE");
......
......@@ -470,12 +470,20 @@ public class DateTimeUtils {
timeZoneStart = s.indexOf('-', dateEnd + 1);
}
if (timeZoneStart >= 0) {
String tzName = "GMT" + s.substring(timeZoneStart);
// Allow [timeZoneName] part after time zone offset
int offsetEnd = s.indexOf('[', timeZoneStart + 1);
if (offsetEnd < 0) {
offsetEnd = s.length();
}
String tzName = "GMT" + s.substring(timeZoneStart, offsetEnd);
tz = TimeZone.getTimeZone(tzName);
if (!tz.getID().startsWith(tzName)) {
throw new IllegalArgumentException(
tzName + " (" + tz.getID() + "?)");
}
if (s.charAt(timeZoneStart - 1) == ' ') {
timeZoneStart--;
}
timeEnd = timeZoneStart;
} else {
timeZoneStart = s.indexOf(' ', dateEnd + 1);
......
......@@ -26,3 +26,12 @@ SELECT * FROM tab_with_timezone ORDER BY X;
> 2018-03-25 01:59:00.0+01
> 2018-03-25 03:00:00.0+02
> rows (ordered): 2
SELECT TIMESTAMP WITH TIME ZONE '2000-01-10 00:00:00 -02' AS A,
TIMESTAMP WITH TIME ZONE '2000-01-10 00:00:00.000000000 +02:00' AS B,
TIMESTAMP WITH TIME ZONE '2000-01-10 00:00:00.000000000+02:00' AS C,
TIMESTAMP WITH TIME ZONE '2000-01-10T00:00:00.000000000+09:00[Asia/Tokyo]' AS D;
> A B C D
> ------------------------ ------------------------ ------------------------ ------------------------
> 2000-01-10 00:00:00.0-02 2000-01-10 00:00:00.0+02 2000-01-10 00:00:00.0+02 2000-01-10 00:00:00.0+09
> rows: 1
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论