Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c312b552
提交
c312b552
authored
1月 09, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use LocalDateTime.toLocalTime() instead of obscured calculations in LocalDateTimeUtils
上级
39f12338
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
6 行增加
和
48 行删除
+6
-48
LocalDateTimeUtils.java
h2/src/main/org/h2/util/LocalDateTimeUtils.java
+6
-48
没有找到文件。
h2/src/main/org/h2/util/LocalDateTimeUtils.java
浏览文件 @
c312b552
...
...
@@ -85,8 +85,8 @@ public class LocalDateTimeUtils {
private
static
final
Method
LOCAL_DATE_TIME_PLUS_NANOS
;
// java.time.LocalDateTime#toLocalDate()
private
static
final
Method
LOCAL_DATE_TIME_TO_LOCAL_DATE
;
// java.time.LocalDateTime#t
runcatedTo(TemporalUnit
)
private
static
final
Method
LOCAL_DATE_TIME_T
RUNCATED_TO
;
// java.time.LocalDateTime#t
oLocalTime(
)
private
static
final
Method
LOCAL_DATE_TIME_T
O_LOCAL_TIME
;
// java.time.LocalDateTime#parse(CharSequence)
private
static
final
Method
LOCAL_DATE_TIME_PARSE
;
...
...
@@ -105,17 +105,8 @@ public class LocalDateTimeUtils {
// java.time.ZoneOffset#getTotalSeconds()
private
static
final
Method
ZONE_OFFSET_GET_TOTAL_SECONDS
;
// java.time.Duration#between(Temporal, Temporal)
private
static
final
Method
DURATION_BETWEEN
;
// java.time.Duration#toNanos()
private
static
final
Method
DURATION_TO_NANOS
;
// java.time.temporal.ChronoUnit#DAYS
private
static
final
Object
CHRONO_UNIT_DAYS
;
private
static
final
boolean
IS_JAVA8_DATE_API_PRESENT
;
static
{
LOCAL_DATE
=
tryGetClass
(
"java.time.LocalDate"
);
LOCAL_TIME
=
tryGetClass
(
"java.time.LocalTime"
);
...
...
@@ -127,12 +118,6 @@ public class LocalDateTimeUtils {
ZONE_OFFSET
!=
null
;
if
(
IS_JAVA8_DATE_API_PRESENT
)
{
Class
<?>
temporalUnit
=
getClass
(
"java.time.temporal.TemporalUnit"
);
Class
<?>
chronoUnit
=
getClass
(
"java.time.temporal.ChronoUnit"
);
Class
<?>
duration
=
getClass
(
"java.time.Duration"
);
Class
<?>
temporal
=
getClass
(
"java.time.temporal.Temporal"
);
LOCAL_TIME_OF_NANO
=
getMethod
(
LOCAL_TIME
,
"ofNanoOfDay"
,
long
.
class
);
LOCAL_TIME_TO_NANO
=
getMethod
(
LOCAL_TIME
,
"toNanoOfDay"
);
...
...
@@ -150,7 +135,7 @@ public class LocalDateTimeUtils {
LOCAL_DATE_TIME_PLUS_NANOS
=
getMethod
(
LOCAL_DATE_TIME
,
"plusNanos"
,
long
.
class
);
LOCAL_DATE_TIME_TO_LOCAL_DATE
=
getMethod
(
LOCAL_DATE_TIME
,
"toLocalDate"
);
LOCAL_DATE_TIME_T
RUNCATED_TO
=
getMethod
(
LOCAL_DATE_TIME
,
"truncatedTo"
,
temporalUnit
);
LOCAL_DATE_TIME_T
O_LOCAL_TIME
=
getMethod
(
LOCAL_DATE_TIME
,
"toLocalTime"
);
LOCAL_DATE_TIME_PARSE
=
getMethod
(
LOCAL_DATE_TIME
,
"parse"
,
CharSequence
.
class
);
ZONE_OFFSET_OF_TOTAL_SECONDS
=
getMethod
(
ZONE_OFFSET
,
"ofTotalSeconds"
,
int
.
class
);
...
...
@@ -162,11 +147,6 @@ public class LocalDateTimeUtils {
OFFSET_DATE_TIME_PARSE
=
getMethod
(
OFFSET_DATE_TIME
,
"parse"
,
CharSequence
.
class
);
ZONE_OFFSET_GET_TOTAL_SECONDS
=
getMethod
(
ZONE_OFFSET
,
"getTotalSeconds"
);
DURATION_BETWEEN
=
getMethod
(
duration
,
"between"
,
temporal
,
temporal
);
DURATION_TO_NANOS
=
getMethod
(
duration
,
"toNanos"
);
CHRONO_UNIT_DAYS
=
getFieldValue
(
chronoUnit
,
"DAYS"
);
}
else
{
LOCAL_TIME_OF_NANO
=
null
;
LOCAL_TIME_TO_NANO
=
null
;
...
...
@@ -179,7 +159,7 @@ public class LocalDateTimeUtils {
LOCAL_TIME_PARSE
=
null
;
LOCAL_DATE_TIME_PLUS_NANOS
=
null
;
LOCAL_DATE_TIME_TO_LOCAL_DATE
=
null
;
LOCAL_DATE_TIME_T
RUNCATED_TO
=
null
;
LOCAL_DATE_TIME_T
O_LOCAL_TIME
=
null
;
LOCAL_DATE_TIME_PARSE
=
null
;
ZONE_OFFSET_OF_TOTAL_SECONDS
=
null
;
OFFSET_DATE_TIME_TO_LOCAL_DATE_TIME
=
null
;
...
...
@@ -187,9 +167,6 @@ public class LocalDateTimeUtils {
OFFSET_DATE_TIME_OF_LOCAL_DATE_TIME_ZONE_OFFSET
=
null
;
OFFSET_DATE_TIME_PARSE
=
null
;
ZONE_OFFSET_GET_TOTAL_SECONDS
=
null
;
DURATION_BETWEEN
=
null
;
DURATION_TO_NANOS
=
null
;
CHRONO_UNIT_DAYS
=
null
;
}
}
...
...
@@ -310,15 +287,6 @@ public class LocalDateTimeUtils {
}
}
private
static
Class
<?>
getClass
(
String
className
)
{
try
{
return
Class
.
forName
(
className
);
}
catch
(
ClassNotFoundException
e
)
{
throw
new
IllegalStateException
(
"Java 8 or later but class "
+
className
+
" is missing"
,
e
);
}
}
private
static
Method
getMethod
(
Class
<?>
clazz
,
String
methodName
,
Class
<?>...
parameterTypes
)
{
try
{
...
...
@@ -330,15 +298,6 @@ public class LocalDateTimeUtils {
}
}
private
static
Object
getFieldValue
(
Class
<?>
clazz
,
String
fieldName
)
{
try
{
return
clazz
.
getField
(
fieldName
).
get
(
null
);
}
catch
(
NoSuchFieldException
|
IllegalAccessException
e
)
{
throw
new
IllegalStateException
(
"Java 8 or later but field "
+
clazz
.
getName
()
+
"#"
+
fieldName
+
" is missing"
,
e
);
}
}
/**
* Checks if the given class is LocalDate.
*
...
...
@@ -566,9 +525,8 @@ public class LocalDateTimeUtils {
private
static
long
timeNanosFromLocalDateTime
(
Object
localDateTime
)
throws
IllegalAccessException
,
InvocationTargetException
{
Object
midnight
=
LOCAL_DATE_TIME_TRUNCATED_TO
.
invoke
(
localDateTime
,
CHRONO_UNIT_DAYS
);
Object
duration
=
DURATION_BETWEEN
.
invoke
(
null
,
midnight
,
localDateTime
);
return
(
Long
)
DURATION_TO_NANOS
.
invoke
(
duration
);
Object
localTime
=
LOCAL_DATE_TIME_TO_LOCAL_TIME
.
invoke
(
localDateTime
);
return
(
Long
)
LOCAL_TIME_TO_NANO
.
invoke
(
localTime
);
}
private
static
short
zoneOffsetToOffsetMinute
(
Object
zoneOffset
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论