Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f4b3e998
提交
f4b3e998
authored
1月 24, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support TIMESTAMP WITH TIME ZONE in some date-time functions
上级
54e2147c
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
88 行增加
和
2 行删除
+88
-2
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+12
-1
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+24
-0
day-of-month.sql
...rg/h2/test/scripts/functions/timeanddate/day-of-month.sql
+19
-0
hour.sql
...c/test/org/h2/test/scripts/functions/timeanddate/hour.sql
+19
-0
TestDateIso8601.java
h2/src/test/org/h2/test/unit/TestDateIso8601.java
+14
-1
没有找到文件。
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
f4b3e998
...
...
@@ -21,6 +21,7 @@ import org.h2.value.ValueDate;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
/**
* This utility class contains time conversion functions.
...
...
@@ -318,14 +319,24 @@ public class DateTimeUtils {
}
private
static
Calendar
valueToCalendar
(
Value
value
)
{
Calendar
cal
=
DateTimeUtils
.
createGregorianCalendar
()
;
Calendar
cal
;
if
(
value
instanceof
ValueTimestamp
)
{
cal
=
createGregorianCalendar
();
cal
.
setTime
(
value
.
getTimestamp
());
}
else
if
(
value
instanceof
ValueDate
)
{
cal
=
createGregorianCalendar
();
cal
.
setTime
(
value
.
getDate
());
}
else
if
(
value
instanceof
ValueTime
)
{
cal
=
createGregorianCalendar
();
cal
.
setTime
(
value
.
getTime
());
}
else
if
(
value
instanceof
ValueTimestampTimeZone
)
{
ValueTimestampTimeZone
v
=
(
ValueTimestampTimeZone
)
value
;
cal
=
createGregorianCalendar
(
TimeZone
.
getTimeZone
(
v
.
getTimeZoneName
()));
cal
.
setTimeInMillis
(
DateTimeUtils
.
convertDateValueToMillis
(
DateTimeUtils
.
UTC
,
v
.
getDateValue
())
+
v
.
getTimeNanos
()
/
1000000L
-
v
.
getTimeZoneOffsetMins
()
*
60000
);
}
else
{
cal
=
createGregorianCalendar
();
cal
.
setTime
(
value
.
getTimestamp
());
}
return
cal
;
...
...
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
f4b3e998
...
...
@@ -201,6 +201,30 @@ public class ValueTimestampTimeZone extends Value {
return
timeZoneOffsetMins
;
}
/**
* Returns name of the timezone such as UTC or GMT+1:00.
*
* @return name of the timezone
*/
public
String
getTimeZoneName
()
{
int
offset
=
timeZoneOffsetMins
;
if
(
offset
==
0
)
return
"UTC"
;
StringBuilder
builder
=
new
StringBuilder
(
"GMT"
);
if
(
offset
>
0
)
{
builder
.
append
(
'+'
);
}
else
{
builder
.
append
(
'-'
);
offset
=
-
offset
;
}
builder
.
append
(
offset
/
60
).
append
(
':'
);
offset
%=
60
;
if
(
offset
<
10
)
builder
.
append
(
'0'
);
builder
.
append
(
offset
);
return
builder
.
toString
();
}
@Override
public
Timestamp
getTimestamp
()
{
throw
new
UnsupportedOperationException
(
"unimplemented"
);
...
...
h2/src/test/org/h2/test/scripts/functions/timeanddate/day-of-month.sql
浏览文件 @
f4b3e998
...
...
@@ -14,3 +14,22 @@ select dayofmonth(date '2005-09-12') d12 from test;
>
---
>
12
>
rows
:
1
drop
table
test
;
>
ok
create
table
test
(
ts
timestamp
with
time
zone
);
>
ok
insert
into
test
(
ts
)
values
(
'2010-05-11 00:00:00+10:00'
),
(
'2010-05-11 00:00:00-10:00'
);
>
update
count
:
2
select
dayofmonth
(
ts
)
d
from
test
;
>
D
>
--
>
11
>
11
>
rows
:
2
drop
table
test
;
>
ok
h2/src/test/org/h2/test/scripts/functions/timeanddate/hour.sql
浏览文件 @
f4b3e998
...
...
@@ -14,3 +14,22 @@ select hour(time '23:10:59') d23 from test;
>
---
>
23
>
rows
:
1
drop
table
test
;
>
ok
create
table
test
(
ts
timestamp
with
time
zone
);
>
ok
insert
into
test
(
ts
)
values
(
'2010-05-11 05:15:10+10:00'
),
(
'2010-05-11 05:15:10-10:00'
);
>
update
count
:
2
select
hour
(
ts
)
h
from
test
;
>
H
>
-
>
5
>
5
>
rows
:
2
drop
table
test
;
>
ok
h2/src/test/org/h2/test/unit/TestDateIso8601.java
浏览文件 @
f4b3e998
...
...
@@ -13,6 +13,7 @@ import org.h2.test.TestBase;
import
org.h2.value.Value
;
import
org.h2.value.ValueDate
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
/**
* Test cases for DateTimeIso8601Utils.
...
...
@@ -20,7 +21,7 @@ import org.h2.value.ValueTimestamp;
public
class
TestDateIso8601
extends
TestBase
{
private
enum
Type
{
DATE
,
TIMESTAMP
;
DATE
,
TIMESTAMP
,
TIMESTAMP_TIMEZONE_0
,
TIMESTAMP_TIMEZONE_PLUS_11
,
TIMESTAMP_TIMEZONE_MINUS_11
;
}
private
static
Type
type
;
...
...
@@ -43,6 +44,12 @@ public class TestDateIso8601 extends TestBase {
return
ValueDate
.
parse
(
s
);
case
TIMESTAMP:
return
ValueTimestamp
.
parse
(
s
);
case
TIMESTAMP_TIMEZONE_0:
return
ValueTimestampTimeZone
.
parse
(
s
+
" 00:00:00.0Z"
);
case
TIMESTAMP_TIMEZONE_PLUS_11:
return
ValueTimestampTimeZone
.
parse
(
s
+
" 00:00:00+11:00"
);
case
TIMESTAMP_TIMEZONE_MINUS_11:
return
ValueTimestampTimeZone
.
parse
(
s
+
" 00:00:00-11:00"
);
default
:
throw
new
IllegalStateException
();
}
...
...
@@ -54,6 +61,12 @@ public class TestDateIso8601 extends TestBase {
doTest
();
type
=
Type
.
TIMESTAMP
;
doTest
();
type
=
Type
.
TIMESTAMP_TIMEZONE_0
;
doTest
();
type
=
Type
.
TIMESTAMP_TIMEZONE_PLUS_11
;
doTest
();
type
=
Type
.
TIMESTAMP_TIMEZONE_MINUS_11
;
doTest
();
}
private
void
doTest
()
throws
Exception
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论