Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5d667744
提交
5d667744
authored
5月 08, 2014
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve method names and add comments to ValueTimestamp and related classes
上级
fb28c029
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
42 行增加
和
30 行删除
+42
-30
ValueDataType.java
h2/src/main/org/h2/mvstore/db/ValueDataType.java
+1
-1
Data.java
h2/src/main/org/h2/store/Data.java
+2
-2
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+6
-6
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+1
-1
Value.java
h2/src/main/org/h2/value/Value.java
+1
-1
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+29
-17
TestDate.java
h2/src/test/org/h2/test/unit/TestDate.java
+2
-2
没有找到文件。
h2/src/main/org/h2/mvstore/db/ValueDataType.java
浏览文件 @
5d667744
...
@@ -261,7 +261,7 @@ public class ValueDataType implements DataType {
...
@@ -261,7 +261,7 @@ public class ValueDataType implements DataType {
case
Value
.
TIMESTAMP
:
{
case
Value
.
TIMESTAMP
:
{
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
long
dateValue
=
ts
.
getDateValue
();
long
dateValue
=
ts
.
getDateValue
();
long
nanos
=
ts
.
getNanos
();
long
nanos
=
ts
.
get
Time
Nanos
();
long
millis
=
nanos
/
1000000
;
long
millis
=
nanos
/
1000000
;
nanos
-=
millis
*
1000000
;
nanos
-=
millis
*
1000000
;
buff
.
put
((
byte
)
type
).
buff
.
put
((
byte
)
type
).
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
5d667744
...
@@ -519,7 +519,7 @@ public class Data {
...
@@ -519,7 +519,7 @@ public class Data {
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
long
dateValue
=
ts
.
getDateValue
();
long
dateValue
=
ts
.
getDateValue
();
writeVarLong
(
dateValue
);
writeVarLong
(
dateValue
);
long
nanos
=
ts
.
getNanos
();
long
nanos
=
ts
.
get
Time
Nanos
();
long
millis
=
nanos
/
1000000
;
long
millis
=
nanos
/
1000000
;
nanos
-=
millis
*
1000000
;
nanos
-=
millis
*
1000000
;
writeVarLong
(
millis
);
writeVarLong
(
millis
);
...
@@ -1006,7 +1006,7 @@ public class Data {
...
@@ -1006,7 +1006,7 @@ public class Data {
if
(
SysProperties
.
STORE_LOCAL_TIME
)
{
if
(
SysProperties
.
STORE_LOCAL_TIME
)
{
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
long
dateValue
=
ts
.
getDateValue
();
long
dateValue
=
ts
.
getDateValue
();
long
nanos
=
ts
.
getNanos
();
long
nanos
=
ts
.
get
Time
Nanos
();
long
millis
=
nanos
/
1000000
;
long
millis
=
nanos
/
1000000
;
nanos
-=
millis
*
1000000
;
nanos
-=
millis
*
1000000
;
return
1
+
getVarLongLen
(
dateValue
)
+
getVarLongLen
(
millis
)
+
return
1
+
getVarLongLen
(
dateValue
)
+
getVarLongLen
(
millis
)
+
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
5d667744
...
@@ -149,7 +149,7 @@ public class DateTimeUtils {
...
@@ -149,7 +149,7 @@ public class DateTimeUtils {
cal
.
clear
();
cal
.
clear
();
cal
.
setLenient
(
true
);
cal
.
setLenient
(
true
);
long
dateValue
=
ts
.
getDateValue
();
long
dateValue
=
ts
.
getDateValue
();
long
nanos
=
ts
.
getNanos
();
long
nanos
=
ts
.
get
Time
Nanos
();
long
millis
=
nanos
/
1000000
;
long
millis
=
nanos
/
1000000
;
nanos
-=
millis
*
1000000
;
nanos
-=
millis
*
1000000
;
long
s
=
millis
/
1000
;
long
s
=
millis
/
1000
;
...
@@ -651,13 +651,13 @@ public class DateTimeUtils {
...
@@ -651,13 +651,13 @@ public class DateTimeUtils {
* timezone.
* timezone.
*
*
* @param dateValue the date value
* @param dateValue the date value
* @param
n
anos the nanoseconds since midnight
* @param
timeN
anos the nanoseconds since midnight
* @return the timestamp
* @return the timestamp
*/
*/
public
static
Timestamp
convertDateValueToTimestamp
(
long
dateValue
,
public
static
Timestamp
convertDateValueToTimestamp
(
long
dateValue
,
long
n
anos
)
{
long
timeN
anos
)
{
long
millis
=
n
anos
/
1000000
;
long
millis
=
timeN
anos
/
1000000
;
n
anos
-=
millis
*
1000000
;
timeN
anos
-=
millis
*
1000000
;
long
s
=
millis
/
1000
;
long
s
=
millis
/
1000
;
millis
-=
s
*
1000
;
millis
-=
s
*
1000
;
long
m
=
s
/
60
;
long
m
=
s
/
60
;
...
@@ -670,7 +670,7 @@ public class DateTimeUtils {
...
@@ -670,7 +670,7 @@ public class DateTimeUtils {
dayFromDateValue
(
dateValue
),
dayFromDateValue
(
dateValue
),
(
int
)
h
,
(
int
)
m
,
(
int
)
s
,
0
);
(
int
)
h
,
(
int
)
m
,
(
int
)
s
,
0
);
Timestamp
ts
=
new
Timestamp
(
ms
);
Timestamp
ts
=
new
Timestamp
(
ms
);
ts
.
setNanos
((
int
)
(
n
anos
+
millis
*
1000000
));
ts
.
setNanos
((
int
)
(
timeN
anos
+
millis
*
1000000
));
return
ts
;
return
ts
;
}
}
...
...
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
5d667744
...
@@ -379,7 +379,7 @@ public class Transfer {
...
@@ -379,7 +379,7 @@ public class Transfer {
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_9
)
{
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_9
)
{
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
ValueTimestamp
ts
=
(
ValueTimestamp
)
v
;
writeLong
(
ts
.
getDateValue
());
writeLong
(
ts
.
getDateValue
());
writeLong
(
ts
.
getNanos
());
writeLong
(
ts
.
get
Time
Nanos
());
}
else
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_7
)
{
}
else
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_7
)
{
Timestamp
ts
=
v
.
getTimestamp
();
Timestamp
ts
=
v
.
getTimestamp
();
writeLong
(
DateTimeUtils
.
getTimeLocalWithoutDst
(
ts
));
writeLong
(
DateTimeUtils
.
getTimeLocalWithoutDst
(
ts
));
...
...
h2/src/main/org/h2/value/Value.java
浏览文件 @
5d667744
...
@@ -732,7 +732,7 @@ public abstract class Value {
...
@@ -732,7 +732,7 @@ public abstract class Value {
return
ValueTime
.
fromNanos
(
0
);
return
ValueTime
.
fromNanos
(
0
);
case
TIMESTAMP:
case
TIMESTAMP:
return
ValueTime
.
fromNanos
(
return
ValueTime
.
fromNanos
(
((
ValueTimestamp
)
this
).
getNanos
());
((
ValueTimestamp
)
this
).
get
Time
Nanos
());
}
}
break
;
break
;
}
}
...
...
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
5d667744
...
@@ -40,23 +40,29 @@ public class ValueTimestamp extends Value {
...
@@ -40,23 +40,29 @@ public class ValueTimestamp extends Value {
*/
*/
static
final
int
DEFAULT_SCALE
=
10
;
static
final
int
DEFAULT_SCALE
=
10
;
/**
* A bit field with bits for the year, month, and day (see DateTimeUtils for encoding)
*/
private
final
long
dateValue
;
private
final
long
dateValue
;
private
final
long
nanos
;
/**
* The nanoseconds since midnight.
*/
private
final
long
timeNanos
;
private
ValueTimestamp
(
long
dateValue
,
long
n
anos
)
{
private
ValueTimestamp
(
long
dateValue
,
long
timeN
anos
)
{
this
.
dateValue
=
dateValue
;
this
.
dateValue
=
dateValue
;
this
.
nanos
=
n
anos
;
this
.
timeNanos
=
timeN
anos
;
}
}
/**
/**
* Get or create a date value for the given date.
* Get or create a date value for the given date.
*
*
* @param dateValue the date value
* @param dateValue the date value
, a bit field with bits for the year, month, and day
* @param
nanos the nanoseconds
* @param
timeNanos the nanoseconds since midnight
* @return the value
* @return the value
*/
*/
public
static
ValueTimestamp
fromDateValueAndNanos
(
long
dateValue
,
long
n
anos
)
{
public
static
ValueTimestamp
fromDateValueAndNanos
(
long
dateValue
,
long
timeN
anos
)
{
return
(
ValueTimestamp
)
Value
.
cache
(
new
ValueTimestamp
(
dateValue
,
n
anos
));
return
(
ValueTimestamp
)
Value
.
cache
(
new
ValueTimestamp
(
dateValue
,
timeN
anos
));
}
}
/**
/**
...
@@ -165,17 +171,23 @@ public class ValueTimestamp extends Value {
...
@@ -165,17 +171,23 @@ public class ValueTimestamp extends Value {
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
nanos
);
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
nanos
);
}
}
/**
* A bit field with bits for the year, month, and day (see DateTimeUtils for encoding)
*/
public
long
getDateValue
()
{
public
long
getDateValue
()
{
return
dateValue
;
return
dateValue
;
}
}
public
long
getNanos
()
{
/**
return
nanos
;
* The nanoseconds since midnight.
*/
public
long
getTimeNanos
()
{
return
timeNanos
;
}
}
@Override
@Override
public
Timestamp
getTimestamp
()
{
public
Timestamp
getTimestamp
()
{
return
DateTimeUtils
.
convertDateValueToTimestamp
(
dateValue
,
n
anos
);
return
DateTimeUtils
.
convertDateValueToTimestamp
(
dateValue
,
timeN
anos
);
}
}
@Override
@Override
...
@@ -188,7 +200,7 @@ public class ValueTimestamp extends Value {
...
@@ -188,7 +200,7 @@ public class ValueTimestamp extends Value {
StringBuilder
buff
=
new
StringBuilder
(
DISPLAY_SIZE
);
StringBuilder
buff
=
new
StringBuilder
(
DISPLAY_SIZE
);
ValueDate
.
appendDate
(
buff
,
dateValue
);
ValueDate
.
appendDate
(
buff
,
dateValue
);
buff
.
append
(
' '
);
buff
.
append
(
' '
);
ValueTime
.
appendTime
(
buff
,
n
anos
,
true
);
ValueTime
.
appendTime
(
buff
,
timeN
anos
,
true
);
return
buff
.
toString
();
return
buff
.
toString
();
}
}
...
@@ -220,7 +232,7 @@ public class ValueTimestamp extends Value {
...
@@ -220,7 +232,7 @@ public class ValueTimestamp extends Value {
if
(
targetScale
<
0
)
{
if
(
targetScale
<
0
)
{
throw
DbException
.
getInvalidValueException
(
"scale"
,
targetScale
);
throw
DbException
.
getInvalidValueException
(
"scale"
,
targetScale
);
}
}
long
n
=
n
anos
;
long
n
=
timeN
anos
;
BigDecimal
bd
=
BigDecimal
.
valueOf
(
n
);
BigDecimal
bd
=
BigDecimal
.
valueOf
(
n
);
bd
=
bd
.
movePointLeft
(
9
);
bd
=
bd
.
movePointLeft
(
9
);
bd
=
ValueDecimal
.
setScale
(
bd
,
targetScale
);
bd
=
ValueDecimal
.
setScale
(
bd
,
targetScale
);
...
@@ -239,7 +251,7 @@ public class ValueTimestamp extends Value {
...
@@ -239,7 +251,7 @@ public class ValueTimestamp extends Value {
if
(
c
!=
0
)
{
if
(
c
!=
0
)
{
return
c
;
return
c
;
}
}
return
MathUtils
.
compareLong
(
nanos
,
t
.
n
anos
);
return
MathUtils
.
compareLong
(
timeNanos
,
t
.
timeN
anos
);
}
}
@Override
@Override
...
@@ -250,12 +262,12 @@ public class ValueTimestamp extends Value {
...
@@ -250,12 +262,12 @@ public class ValueTimestamp extends Value {
return
false
;
return
false
;
}
}
ValueTimestamp
x
=
(
ValueTimestamp
)
other
;
ValueTimestamp
x
=
(
ValueTimestamp
)
other
;
return
dateValue
==
x
.
dateValue
&&
nanos
==
x
.
n
anos
;
return
dateValue
==
x
.
dateValue
&&
timeNanos
==
x
.
timeN
anos
;
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
(
int
)
(
dateValue
^
(
dateValue
>>>
32
)
^
nanos
^
(
n
anos
>>>
32
));
return
(
int
)
(
dateValue
^
(
dateValue
>>>
32
)
^
timeNanos
^
(
timeN
anos
>>>
32
));
}
}
@Override
@Override
...
@@ -274,7 +286,7 @@ public class ValueTimestamp extends Value {
...
@@ -274,7 +286,7 @@ public class ValueTimestamp extends Value {
ValueTimestamp
t
=
(
ValueTimestamp
)
v
.
convertTo
(
Value
.
TIMESTAMP
);
ValueTimestamp
t
=
(
ValueTimestamp
)
v
.
convertTo
(
Value
.
TIMESTAMP
);
long
d1
=
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
);
long
d1
=
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
);
long
d2
=
DateTimeUtils
.
absoluteDayFromDateValue
(
t
.
dateValue
);
long
d2
=
DateTimeUtils
.
absoluteDayFromDateValue
(
t
.
dateValue
);
return
DateTimeUtils
.
normalizeTimestamp
(
d1
+
d2
,
nanos
+
t
.
n
anos
);
return
DateTimeUtils
.
normalizeTimestamp
(
d1
+
d2
,
timeNanos
+
t
.
timeN
anos
);
}
}
@Override
@Override
...
@@ -282,7 +294,7 @@ public class ValueTimestamp extends Value {
...
@@ -282,7 +294,7 @@ public class ValueTimestamp extends Value {
ValueTimestamp
t
=
(
ValueTimestamp
)
v
.
convertTo
(
Value
.
TIMESTAMP
);
ValueTimestamp
t
=
(
ValueTimestamp
)
v
.
convertTo
(
Value
.
TIMESTAMP
);
long
d1
=
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
);
long
d1
=
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
);
long
d2
=
DateTimeUtils
.
absoluteDayFromDateValue
(
t
.
dateValue
);
long
d2
=
DateTimeUtils
.
absoluteDayFromDateValue
(
t
.
dateValue
);
return
DateTimeUtils
.
normalizeTimestamp
(
d1
-
d2
,
nanos
-
t
.
n
anos
);
return
DateTimeUtils
.
normalizeTimestamp
(
d1
-
d2
,
timeNanos
-
t
.
timeN
anos
);
}
}
}
}
h2/src/test/org/h2/test/unit/TestDate.java
浏览文件 @
5d667744
...
@@ -234,7 +234,7 @@ public class TestDate extends TestBase {
...
@@ -234,7 +234,7 @@ public class TestDate extends TestBase {
assertEquals
(
"TIMESTAMP '2001-01-01 01:01:01.111'"
,
t1
.
toString
());
assertEquals
(
"TIMESTAMP '2001-01-01 01:01:01.111'"
,
t1
.
toString
());
assertEquals
(
Value
.
TIMESTAMP
,
t1
.
getType
());
assertEquals
(
Value
.
TIMESTAMP
,
t1
.
getType
());
long
dateValue
=
t1
.
getDateValue
();
long
dateValue
=
t1
.
getDateValue
();
long
nanos
=
t1
.
getNanos
();
long
nanos
=
t1
.
get
Time
Nanos
();
assertEquals
((
int
)
((
dateValue
>>>
32
)
^
dateValue
^
assertEquals
((
int
)
((
dateValue
>>>
32
)
^
dateValue
^
(
nanos
>>>
32
)
^
nanos
),
(
nanos
>>>
32
)
^
nanos
),
t1
.
hashCode
());
t1
.
hashCode
());
...
@@ -311,7 +311,7 @@ public class TestDate extends TestBase {
...
@@ -311,7 +311,7 @@ public class TestDate extends TestBase {
assertEquals
(
0
,
DateTimeUtils
.
absoluteDayFromDateValue
(
assertEquals
(
0
,
DateTimeUtils
.
absoluteDayFromDateValue
(
ValueTimestamp
.
parse
(
"1970-01-01"
).
getDateValue
()));
ValueTimestamp
.
parse
(
"1970-01-01"
).
getDateValue
()));
assertEquals
(
0
,
ValueTimestamp
.
parse
(
assertEquals
(
0
,
ValueTimestamp
.
parse
(
"1970-01-01"
).
getNanos
());
"1970-01-01"
).
get
Time
Nanos
());
assertEquals
(
0
,
ValueTimestamp
.
parse
(
assertEquals
(
0
,
ValueTimestamp
.
parse
(
"1970-01-01 00:00:00.000 UTC"
).
getTimestamp
().
getTime
());
"1970-01-01 00:00:00.000 UTC"
).
getTimestamp
().
getTime
());
assertEquals
(
0
,
ValueTimestamp
.
parse
(
assertEquals
(
0
,
ValueTimestamp
.
parse
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论