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