Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
dde366b2
Unverified
提交
dde366b2
authored
1月 15, 2018
作者:
Noel Grandin
提交者:
GitHub
1月 15, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #766 from katzyn/DateTimeUtils
Minor clean up of DateTimeUtils
上级
58e4f59f
b82bdd8d
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
23 行增加
和
25 行删除
+23
-25
Function.java
h2/src/main/org/h2/expression/Function.java
+2
-3
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+2
-1
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+13
-13
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+1
-1
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+3
-5
TestResultSet.java
h2/src/test/org/h2/test/jdbc/TestResultSet.java
+1
-1
TestDate.java
h2/src/test/org/h2/test/unit/TestDate.java
+1
-1
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
dde366b2
...
...
@@ -1856,8 +1856,7 @@ public class Function extends Expression implements FunctionCall {
int
nanos
=
d
.
getNanos
()
%
1000000
;
calendar
.
setTime
(
d
);
calendar
.
add
(
field
,
(
int
)
count
);
long
t
=
calendar
.
getTime
().
getTime
();
Timestamp
ts
=
new
Timestamp
(
t
);
Timestamp
ts
=
new
Timestamp
(
calendar
.
getTimeInMillis
());
ts
.
setNanos
(
ts
.
getNanos
()
+
nanos
);
return
ts
;
}
...
...
@@ -1926,7 +1925,7 @@ public class Function extends Expression implements FunctionCall {
default
:
break
;
}
calendar
=
DateTimeUtils
.
createGregorianCalendar
(
TimeZone
.
getTimeZone
(
"UTC"
)
);
calendar
=
DateTimeUtils
.
createGregorianCalendar
(
DateTimeUtils
.
UTC
);
calendar
.
setTimeInMillis
(
t1
);
int
year1
=
calendar
.
get
(
Calendar
.
YEAR
);
int
month1
=
calendar
.
get
(
Calendar
.
MONTH
);
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
dde366b2
...
...
@@ -31,6 +31,7 @@ import org.h2.message.DbException;
import
org.h2.server.Service
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
...
...
@@ -257,7 +258,7 @@ public class WebServer implements Service {
if
(
startDateTime
==
null
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"EEE, d MMM yyyy HH:mm:ss z"
,
new
Locale
(
"en"
,
""
));
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
)
);
format
.
setTimeZone
(
DateTimeUtils
.
UTC
);
startDateTime
=
format
.
format
(
System
.
currentTimeMillis
());
}
return
startDateTime
;
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
dde366b2
...
...
@@ -35,6 +35,11 @@ public class DateTimeUtils {
*/
public
static
final
long
MILLIS_PER_DAY
=
24
*
60
*
60
*
1000L
;
/**
* UTC time zone.
*/
public
static
final
TimeZone
UTC
=
TimeZone
.
getTimeZone
(
"UTC"
);
private
static
final
long
NANOS_PER_DAY
=
MILLIS_PER_DAY
*
1000000
;
private
static
final
int
SHIFT_YEAR
=
9
;
...
...
@@ -163,10 +168,9 @@ public class DateTimeUtils {
cal
.
clear
();
cal
.
setLenient
(
true
);
long
dateValue
=
d
.
getDateValue
();
setCalendarField
s
(
cal
,
yearFromDateValue
(
dateValue
),
long
ms
=
convertToMilli
s
(
cal
,
yearFromDateValue
(
dateValue
),
monthFromDateValue
(
dateValue
),
dayFromDateValue
(
dateValue
),
0
,
0
,
0
,
0
);
long
ms
=
cal
.
getTimeInMillis
();
return
new
Date
(
ms
);
}
...
...
@@ -194,10 +198,7 @@ public class DateTimeUtils {
s
-=
m
*
60
;
long
h
=
m
/
60
;
m
-=
h
*
60
;
setCalendarFields
(
cal
,
1970
,
1
,
1
,
(
int
)
h
,
(
int
)
m
,
(
int
)
s
,
(
int
)
millis
);
long
ms
=
cal
.
getTimeInMillis
();
return
new
Time
(
ms
);
return
new
Time
(
convertToMillis
(
cal
,
1970
,
1
,
1
,
(
int
)
h
,
(
int
)
m
,
(
int
)
s
,
(
int
)
millis
));
}
/**
...
...
@@ -225,10 +226,9 @@ public class DateTimeUtils {
s
-=
m
*
60
;
long
h
=
m
/
60
;
m
-=
h
*
60
;
setCalendarField
s
(
cal
,
yearFromDateValue
(
dateValue
),
long
ms
=
convertToMilli
s
(
cal
,
yearFromDateValue
(
dateValue
),
monthFromDateValue
(
dateValue
),
dayFromDateValue
(
dateValue
),
(
int
)
h
,
(
int
)
m
,
(
int
)
s
,
(
int
)
millis
);
long
ms
=
cal
.
getTimeInMillis
();
Timestamp
x
=
new
Timestamp
(
ms
);
x
.
setNanos
((
int
)
(
nanos
+
millis
*
1000000
));
return
x
;
...
...
@@ -283,7 +283,7 @@ public class DateTimeUtils {
Calendar
local
=
DateTimeUtils
.
createGregorianCalendar
();
local
.
setTime
(
x
);
convertTime
(
local
,
target
);
return
target
.
getTime
().
getTime
();
return
target
.
getTime
InMillis
();
}
private
static
void
convertTime
(
Calendar
from
,
Calendar
to
)
{
...
...
@@ -468,12 +468,11 @@ public class DateTimeUtils {
c
=
getCalendar
(
tz
);
}
c
.
setLenient
(
lenient
);
setCalendarFields
(
c
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
return
c
.
getTime
().
getTime
();
return
convertToMillis
(
c
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
private
static
void
setCalendarFields
(
Calendar
cal
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
private
static
long
convertToMillis
(
Calendar
cal
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
if
(
year
<=
0
)
{
cal
.
set
(
Calendar
.
ERA
,
GregorianCalendar
.
BC
);
cal
.
set
(
Calendar
.
YEAR
,
1
-
year
);
...
...
@@ -488,6 +487,7 @@ public class DateTimeUtils {
cal
.
set
(
Calendar
.
MINUTE
,
minute
);
cal
.
set
(
Calendar
.
SECOND
,
second
);
cal
.
set
(
Calendar
.
MILLISECOND
,
millis
);
return
cal
.
getTimeInMillis
();
}
/**
...
...
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
dde366b2
...
...
@@ -172,7 +172,7 @@ public class ValueTimestamp extends Value {
int
timeEnd
=
s
.
length
();
TimeZone
tz
=
null
;
if
(
s
.
endsWith
(
"Z"
))
{
tz
=
TimeZone
.
getTimeZone
(
"UTC"
)
;
tz
=
DateTimeUtils
.
UTC
;
timeEnd
--;
}
else
{
int
timeZoneStart
=
s
.
indexOf
(
'+'
,
dateEnd
+
1
);
...
...
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
dde366b2
...
...
@@ -40,8 +40,6 @@ public class ValueTimestampTimeZone extends Value {
*/
static
final
int
DEFAULT_SCALE
=
10
;
private
static
final
TimeZone
GMT_TIMEZONE
=
TimeZone
.
getTimeZone
(
"GMT"
);
/**
* A bit field with bits for the year, month, and day (see DateTimeUtils for
* encoding)
...
...
@@ -165,7 +163,7 @@ public class ValueTimestampTimeZone extends Value {
}
if
(
tz
!=
null
)
{
long
millis
=
DateTimeUtils
.
convertDateValueToMillis
(
GMT_TIMEZONE
,
dateValue
);
.
convertDateValueToMillis
(
DateTimeUtils
.
UTC
,
dateValue
);
tzMinutes
=
(
short
)
(
tz
.
getOffset
(
millis
)
/
1000
/
60
);
}
}
...
...
@@ -294,7 +292,7 @@ public class ValueTimestampTimeZone extends Value {
// convert to minutes and add timezone offset
long
a
=
DateTimeUtils
.
convertDateValueToMillis
(
TimeZone
.
getTimeZone
(
"UTC"
)
,
dateValue
)
/
DateTimeUtils
.
UTC
,
dateValue
)
/
(
1000L
*
60L
);
long
ma
=
timeNanos
/
(
1000L
*
1000L
*
1000L
*
60L
);
a
+=
ma
;
...
...
@@ -302,7 +300,7 @@ public class ValueTimestampTimeZone extends Value {
// convert to minutes and add timezone offset
long
b
=
DateTimeUtils
.
convertDateValueToMillis
(
TimeZone
.
getTimeZone
(
"UTC"
)
,
t
.
dateValue
)
/
DateTimeUtils
.
UTC
,
t
.
dateValue
)
/
(
1000L
*
60L
);
long
mb
=
t
.
timeNanos
/
(
1000L
*
1000L
*
1000L
*
60L
);
b
+=
mb
;
...
...
h2/src/test/org/h2/test/jdbc/TestResultSet.java
浏览文件 @
dde366b2
...
...
@@ -1309,7 +1309,7 @@ public class TestResultSet extends TestBase {
java
.
sql
.
Timestamp
.
valueOf
(
"2011-11-11 00:00:00.0"
).
getTime
());
o
=
rs
.
getObject
(
2
,
Calendar
.
class
);
assertTrue
(
o
instanceof
Calendar
);
assertEquals
(((
Calendar
)
o
).
getTime
().
getTime
(),
assertEquals
(((
Calendar
)
o
).
getTime
InMillis
(),
java
.
sql
.
Timestamp
.
valueOf
(
"2011-11-11 00:00:00.0"
).
getTime
());
rs
.
next
();
...
...
h2/src/test/org/h2/test/unit/TestDate.java
浏览文件 @
dde366b2
...
...
@@ -352,7 +352,7 @@ public class TestDate extends TestBase {
}
private
void
testValidDate
()
{
Calendar
c
=
DateTimeUtils
.
createGregorianCalendar
(
TimeZone
.
getTimeZone
(
"UTC"
)
);
Calendar
c
=
DateTimeUtils
.
createGregorianCalendar
(
DateTimeUtils
.
UTC
);
c
.
setLenient
(
false
);
for
(
int
y
=
-
2000
;
y
<
3000
;
y
++)
{
for
(
int
m
=
-
3
;
m
<=
14
;
m
++)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论