Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c5995d72
提交
c5995d72
authored
2月 01, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use dateValueFromDate() and nanosFromDate() in parseTimestamp()
上级
73ac0e4d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
38 行删除
+31
-38
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+3
-38
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+28
-0
没有找到文件。
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
c5995d72
...
@@ -270,35 +270,6 @@ public class DateTimeUtils {
...
@@ -270,35 +270,6 @@ public class DateTimeUtils {
return
ValueTime
.
fromNanos
(
nanos
);
return
ValueTime
.
fromNanos
(
nanos
);
}
}
/**
* Convert a date to the specified time zone.
*
* @param x the date to convert
* @param target the calendar with the target timezone
* @return the milliseconds in UTC
*/
public
static
long
convertToLocal
(
java
.
util
.
Date
x
,
Calendar
target
)
{
if
(
target
==
null
)
{
throw
DbException
.
getInvalidValueException
(
"calendar"
,
null
);
}
target
=
(
Calendar
)
target
.
clone
();
Calendar
local
=
DateTimeUtils
.
createGregorianCalendar
();
local
.
setTime
(
x
);
convertTime
(
local
,
target
);
return
target
.
getTimeInMillis
();
}
private
static
void
convertTime
(
Calendar
from
,
Calendar
to
)
{
to
.
set
(
Calendar
.
ERA
,
from
.
get
(
Calendar
.
ERA
));
to
.
set
(
Calendar
.
YEAR
,
from
.
get
(
Calendar
.
YEAR
));
to
.
set
(
Calendar
.
MONTH
,
from
.
get
(
Calendar
.
MONTH
));
to
.
set
(
Calendar
.
DAY_OF_MONTH
,
from
.
get
(
Calendar
.
DAY_OF_MONTH
));
to
.
set
(
Calendar
.
HOUR_OF_DAY
,
from
.
get
(
Calendar
.
HOUR_OF_DAY
));
to
.
set
(
Calendar
.
MINUTE
,
from
.
get
(
Calendar
.
MINUTE
));
to
.
set
(
Calendar
.
SECOND
,
from
.
get
(
Calendar
.
SECOND
));
to
.
set
(
Calendar
.
MILLISECOND
,
from
.
get
(
Calendar
.
MILLISECOND
));
}
/**
/**
* Convert the timestamp using the specified calendar.
* Convert the timestamp using the specified calendar.
*
*
...
@@ -519,15 +490,9 @@ public class DateTimeUtils {
...
@@ -519,15 +490,9 @@ public class DateTimeUtils {
tzMinutes
=
(
short
)
(
tz
.
getOffset
(
millis
)
/
1000
/
60
);
tzMinutes
=
(
short
)
(
tz
.
getOffset
(
millis
)
/
1000
/
60
);
}
}
}
else
{
}
else
{
long
ms
=
nanos
/
1000000
;
long
millis
=
convertDateTimeValueToMillis
(
tz
,
dateValue
,
nanos
/
1000000
);
nanos
-=
ms
*
1000000
;
dateValue
=
dateValueFromDate
(
millis
);
long
millis
=
convertDateTimeValueToMillis
(
tz
,
dateValue
,
ms
);
nanos
=
nanos
%
1000000
+
nanosFromDate
(
millis
);
ms
=
convertToLocal
(
new
Date
(
millis
),
createGregorianCalendar
(
UTC
));
long
md
=
MILLIS_PER_DAY
;
long
absoluteDay
=
(
ms
>=
0
?
ms
:
ms
-
md
+
1
)
/
md
;
dateValue
=
dateValueFromAbsoluteDay
(
absoluteDay
);
ms
-=
absoluteDay
*
md
;
nanos
+=
ms
*
1000000
;
}
}
}
}
}
}
...
...
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
c5995d72
...
@@ -15,6 +15,8 @@ import java.sql.Time;
...
@@ -15,6 +15,8 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Calendar
;
import
java.util.TimeZone
;
import
java.util.UUID
;
import
java.util.UUID
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
...
@@ -35,6 +37,7 @@ import org.h2.value.ValueLobDb;
...
@@ -35,6 +37,7 @@ import org.h2.value.ValueLobDb;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueResultSet
;
import
org.h2.value.ValueResultSet
;
import
org.h2.value.ValueString
;
import
org.h2.value.ValueString
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueUuid
;
import
org.h2.value.ValueUuid
;
/**
/**
...
@@ -61,6 +64,7 @@ public class TestValue extends TestBase {
...
@@ -61,6 +64,7 @@ public class TestValue extends TestBase {
testUUID
();
testUUID
();
testDouble
(
false
);
testDouble
(
false
);
testDouble
(
true
);
testDouble
(
true
);
testTimestamp
();
testModulusDouble
();
testModulusDouble
();
testModulusDecimal
();
testModulusDecimal
();
testModulusOperator
();
testModulusOperator
();
...
@@ -302,6 +306,30 @@ public class TestValue extends TestBase {
...
@@ -302,6 +306,30 @@ public class TestValue extends TestBase {
}
}
}
}
private
void
testTimestamp
()
{
ValueTimestamp
vts
=
ValueTimestamp
.
parse
(
"2000-01-15 10:20:30.333222111"
);
Timestamp
ts
=
Timestamp
.
valueOf
(
"2000-01-15 10:20:30.333222111"
);
assertEquals
(
ts
.
toString
(),
vts
.
getString
());
assertEquals
(
ts
,
vts
.
getTimestamp
());
Calendar
c
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"Europe/Berlin"
));
c
.
set
(
2018
,
02
,
25
,
1
,
59
,
00
);
c
.
set
(
Calendar
.
MILLISECOND
,
123
);
long
expected
=
c
.
getTimeInMillis
();
ts
=
ValueTimestamp
.
parse
(
"2018-03-25 01:59:00.123123123 Europe/Berlin"
).
getTimestamp
();
assertEquals
(
expected
,
ts
.
getTime
());
assertEquals
(
123123123
,
ts
.
getNanos
());
ts
=
ValueTimestamp
.
parse
(
"2018-03-25 01:59:00.123123123+01"
).
getTimestamp
();
assertEquals
(
expected
,
ts
.
getTime
());
assertEquals
(
123123123
,
ts
.
getNanos
());
expected
+=
60000
;
// 1 minute
ts
=
ValueTimestamp
.
parse
(
"2018-03-25 03:00:00.123123123 Europe/Berlin"
).
getTimestamp
();
assertEquals
(
expected
,
ts
.
getTime
());
assertEquals
(
123123123
,
ts
.
getNanos
());
ts
=
ValueTimestamp
.
parse
(
"2018-03-25 03:00:00.123123123+02"
).
getTimestamp
();
assertEquals
(
expected
,
ts
.
getTime
());
assertEquals
(
123123123
,
ts
.
getNanos
());
}
private
void
testUUID
()
{
private
void
testUUID
()
{
long
maxHigh
=
0
,
maxLow
=
0
,
minHigh
=
-
1L
,
minLow
=
-
1L
;
long
maxHigh
=
0
,
maxLow
=
0
,
minHigh
=
-
1L
,
minLow
=
-
1L
;
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论