Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9c97f812
Unverified
提交
9c97f812
authored
1月 06, 2018
作者:
Noel Grandin
提交者:
GitHub
1月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #708 from katzyn/LocalDate
Fix for issue #644: Year changing from negative -509 to a positive 510
上级
50d287a2
7a1ca278
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
26 行删除
+15
-26
LocalDateTimeUtils.java
h2/src/main/org/h2/util/LocalDateTimeUtils.java
+8
-26
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+7
-0
没有找到文件。
h2/src/main/org/h2/util/LocalDateTimeUtils.java
浏览文件 @
9c97f812
...
@@ -9,7 +9,6 @@ package org.h2.util;
...
@@ -9,7 +9,6 @@ package org.h2.util;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.sql.Date
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -60,15 +59,9 @@ public class LocalDateTimeUtils {
...
@@ -60,15 +59,9 @@ public class LocalDateTimeUtils {
// Class<java.time.ZoneOffset>
// Class<java.time.ZoneOffset>
private
static
final
Class
<?>
ZONE_OFFSET
;
private
static
final
Class
<?>
ZONE_OFFSET
;
// java.sql.Date#toLocalDate()
private
static
final
Method
TO_LOCAL_DATE
;
// java.time.LocalTime#ofNanoOfDay()
// java.time.LocalTime#ofNanoOfDay()
private
static
final
Method
LOCAL_TIME_OF_NANO
;
private
static
final
Method
LOCAL_TIME_OF_NANO
;
// java.sql.Date#valueOf(LocalDate)
private
static
final
Method
DATE_VALUE_OF
;
// java.time.LocalTime#toNanoOfDay()
// java.time.LocalTime#toNanoOfDay()
private
static
final
Method
LOCAL_TIME_TO_NANO
;
private
static
final
Method
LOCAL_TIME_TO_NANO
;
...
@@ -140,12 +133,8 @@ public class LocalDateTimeUtils {
...
@@ -140,12 +133,8 @@ public class LocalDateTimeUtils {
Class
<?>
duration
=
getClass
(
"java.time.Duration"
);
Class
<?>
duration
=
getClass
(
"java.time.Duration"
);
Class
<?>
temporal
=
getClass
(
"java.time.temporal.Temporal"
);
Class
<?>
temporal
=
getClass
(
"java.time.temporal.Temporal"
);
TO_LOCAL_DATE
=
getMethod
(
java
.
sql
.
Date
.
class
,
"toLocalDate"
);
LOCAL_TIME_OF_NANO
=
getMethod
(
LOCAL_TIME
,
"ofNanoOfDay"
,
long
.
class
);
LOCAL_TIME_OF_NANO
=
getMethod
(
LOCAL_TIME
,
"ofNanoOfDay"
,
long
.
class
);
DATE_VALUE_OF
=
getMethod
(
java
.
sql
.
Date
.
class
,
"valueOf"
,
LOCAL_DATE
);
LOCAL_TIME_TO_NANO
=
getMethod
(
LOCAL_TIME
,
"toNanoOfDay"
);
LOCAL_TIME_TO_NANO
=
getMethod
(
LOCAL_TIME
,
"toNanoOfDay"
);
LOCAL_DATE_OF_YEAR_MONTH_DAY
=
getMethod
(
LOCAL_DATE
,
"of"
,
LOCAL_DATE_OF_YEAR_MONTH_DAY
=
getMethod
(
LOCAL_DATE
,
"of"
,
...
@@ -179,9 +168,7 @@ public class LocalDateTimeUtils {
...
@@ -179,9 +168,7 @@ public class LocalDateTimeUtils {
CHRONO_UNIT_DAYS
=
getFieldValue
(
chronoUnit
,
"DAYS"
);
CHRONO_UNIT_DAYS
=
getFieldValue
(
chronoUnit
,
"DAYS"
);
}
else
{
}
else
{
TO_LOCAL_DATE
=
null
;
LOCAL_TIME_OF_NANO
=
null
;
LOCAL_TIME_OF_NANO
=
null
;
DATE_VALUE_OF
=
null
;
LOCAL_TIME_TO_NANO
=
null
;
LOCAL_TIME_TO_NANO
=
null
;
LOCAL_DATE_OF_YEAR_MONTH_DAY
=
null
;
LOCAL_DATE_OF_YEAR_MONTH_DAY
=
null
;
LOCAL_DATE_PARSE
=
null
;
LOCAL_DATE_PARSE
=
null
;
...
@@ -409,7 +396,13 @@ public class LocalDateTimeUtils {
...
@@ -409,7 +396,13 @@ public class LocalDateTimeUtils {
* @return the LocalDate
* @return the LocalDate
*/
*/
public
static
Object
valueToLocalDate
(
Value
value
)
{
public
static
Object
valueToLocalDate
(
Value
value
)
{
return
dateToLocalDate
(
value
.
getDate
());
try
{
return
localDateFromDateValue
(((
ValueDate
)
value
.
convertTo
(
Value
.
DATE
)).
getDateValue
());
}
catch
(
IllegalAccessException
e
)
{
throw
DbException
.
convert
(
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
DbException
.
convertInvocation
(
e
,
"date conversion failed"
);
}
}
}
/**
/**
...
@@ -431,16 +424,6 @@ public class LocalDateTimeUtils {
...
@@ -431,16 +424,6 @@ public class LocalDateTimeUtils {
}
}
}
}
private
static
Object
dateToLocalDate
(
Date
date
)
{
try
{
return
TO_LOCAL_DATE
.
invoke
(
date
);
}
catch
(
IllegalAccessException
e
)
{
throw
DbException
.
convert
(
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
DbException
.
convertInvocation
(
e
,
"date conversion failed"
);
}
}
/**
/**
* Converts a value to a LocalDateTime.
* Converts a value to a LocalDateTime.
*
*
...
@@ -506,8 +489,7 @@ public class LocalDateTimeUtils {
...
@@ -506,8 +489,7 @@ public class LocalDateTimeUtils {
*/
*/
public
static
Value
localDateToDateValue
(
Object
localDate
)
{
public
static
Value
localDateToDateValue
(
Object
localDate
)
{
try
{
try
{
Date
date
=
(
Date
)
DATE_VALUE_OF
.
invoke
(
null
,
localDate
);
return
ValueDate
.
fromDateValue
(
dateValueFromLocalDate
(
localDate
));
return
ValueDate
.
get
(
date
);
}
catch
(
IllegalAccessException
e
)
{
}
catch
(
IllegalAccessException
e
)
{
throw
DbException
.
convert
(
e
);
throw
DbException
.
convert
(
e
);
}
catch
(
InvocationTargetException
e
)
{
}
catch
(
InvocationTargetException
e
)
{
...
...
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
9c97f812
...
@@ -634,6 +634,13 @@ public class TestPreparedStatement extends TestBase {
...
@@ -634,6 +634,13 @@ public class TestPreparedStatement extends TestBase {
Object
localDate2
=
rs
.
getObject
(
1
,
LocalDateTimeUtils
.
getLocalDateClass
());
Object
localDate2
=
rs
.
getObject
(
1
,
LocalDateTimeUtils
.
getLocalDateClass
());
assertEquals
(
localDate
,
localDate2
);
assertEquals
(
localDate
,
localDate2
);
rs
.
close
();
rs
.
close
();
localDate
=
LocalDateTimeUtils
.
parseLocalDate
(
"-0509-01-01"
);
prep
.
setObject
(
1
,
localDate
);
rs
=
prep
.
executeQuery
();
rs
.
next
();
localDate2
=
rs
.
getObject
(
1
,
LocalDateTimeUtils
.
getLocalDateClass
());
assertEquals
(
localDate
,
localDate2
);
rs
.
close
();
}
}
private
void
testTime8
(
Connection
conn
)
throws
SQLException
{
private
void
testTime8
(
Connection
conn
)
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论