Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
adfa0261
提交
adfa0261
authored
8 年前
作者:
Dmitriy Vetutnev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix compare TIMESTAMP WITH TIMEZONE
上级
91b2048d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
6 行删除
+50
-6
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+12
-6
TestTimeStampWithTimeZone.java
h2/src/test/org/h2/test/unit/TestTimeStampWithTimeZone.java
+38
-0
没有找到文件。
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
adfa0261
...
...
@@ -290,15 +290,21 @@ public class ValueTimestampTimeZone extends Value {
@Override
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueTimestampTimeZone
t
=
(
ValueTimestampTimeZone
)
o
;
int
c
=
MathUtils
.
compareLong
(
dateValue
,
t
.
dateValue
);
long
a
=
DateTimeUtils
.
convertDateValueToMillis
(
TimeZone
.
getTimeZone
(
"UTC"
),
dateValue
)
/
(
1000L
*
60L
);
long
ma
=
timeNanos
/
(
1000L
*
1000L
*
1000L
*
60L
);
a
+=
ma
;
a
-=
timeZoneOffsetMins
;
long
b
=
DateTimeUtils
.
convertDateValueToMillis
(
TimeZone
.
getTimeZone
(
"UTC"
),
t
.
dateValue
)
/
(
1000L
*
60L
);
long
mb
=
t
.
timeNanos
/
(
1000L
*
1000L
*
1000L
*
60L
);
b
+=
mb
;
b
-=
t
.
timeZoneOffsetMins
;
int
c
=
MathUtils
.
compareLong
(
a
,
b
);
if
(
c
!=
0
)
{
return
c
;
}
c
=
MathUtils
.
compareLong
(
timeNanos
,
t
.
timeNanos
);
if
(
c
!=
0
)
{
return
c
;
}
return
MathUtils
.
compareInt
(
timeZoneOffsetMins
,
t
.
timeZoneOffsetMins
);
long
na
=
timeNanos
-
(
ma
*
1000L
*
1000L
*
1000L
*
60L
);
long
nb
=
t
.
timeNanos
-
(
mb
*
1000L
*
1000L
*
1000L
*
60L
);
return
MathUtils
.
compareLong
(
na
,
nb
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestTimeStampWithTimeZone.java
浏览文件 @
adfa0261
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.test.TestBase
;
import
org.h2.value.ValueTimestampTimeZone
;
/**
*/
...
...
@@ -29,6 +30,10 @@ public class TestTimeStampWithTimeZone extends TestBase {
public
void
test
()
throws
SQLException
{
deleteDb
(
getTestName
());
test1
();
test2
();
test3
();
test4
();
testOrder
();
deleteDb
(
getTestName
());
}
...
...
@@ -81,4 +86,37 @@ public class TestTimeStampWithTimeZone extends TestBase {
conn
.
close
();
}
private
void
test2
()
{
ValueTimestampTimeZone
a
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 12:00:00.00+00:15"
);
ValueTimestampTimeZone
b
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 12:00:01.00+01:15"
);
int
c
=
a
.
compareTo
(
b
,
null
);
assertEquals
(
c
,
1
);
}
private
void
test3
()
{
ValueTimestampTimeZone
a
=
ValueTimestampTimeZone
.
parse
(
"1970-01-02 00:00:02.00+01:15"
);
ValueTimestampTimeZone
b
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 23:00:01.00+00:15"
);
int
c
=
a
.
compareTo
(
b
,
null
);
assertEquals
(
c
,
1
);
}
private
void
test4
()
{
ValueTimestampTimeZone
a
=
ValueTimestampTimeZone
.
parse
(
"1970-01-02 00:00:01.00+01:15"
);
ValueTimestampTimeZone
b
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 23:00:01.00+00:15"
);
int
c
=
a
.
compareTo
(
b
,
null
);
assertEquals
(
c
,
0
);
}
private
void
testOrder
()
throws
SQLException
{
Connection
conn
=
getConnection
(
getTestName
());
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test_order(id identity, t1 timestamp with timezone)"
);
stat
.
execute
(
"insert into test_order(t1) values('1970-01-01 12:00:00.00+00:15')"
);
stat
.
execute
(
"insert into test_order(t1) values('1970-01-01 12:00:01.00+01:15')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select t1 from test_order order by t1"
);
rs
.
next
();
assertEquals
(
"1970-01-01 12:00:01.0+01:15"
,
rs
.
getString
(
1
));
conn
.
close
();
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论