Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a1cf2956
Unverified
提交
a1cf2956
authored
2月 06, 2018
作者:
Noel Grandin
提交者:
GitHub
2月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #835 from katzyn/datetime2
Inline getTimeTry() into DateTimeUtils.getMillis()
上级
57945c49
f38de87b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
30 行删除
+19
-30
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+19
-30
没有找到文件。
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
a1cf2956
...
...
@@ -67,12 +67,12 @@ public class DateTimeUtils {
* have that problem, and while it is still a small memory leak, it is not a
* class loader memory leak.
*/
private
static
final
ThreadLocal
<
Calendar
>
CACHED_CALENDAR
=
new
ThreadLocal
<>();
private
static
final
ThreadLocal
<
Gregorian
Calendar
>
CACHED_CALENDAR
=
new
ThreadLocal
<>();
/**
* A cached instance of Calendar used when a timezone is specified.
*/
private
static
final
ThreadLocal
<
Calendar
>
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
=
private
static
final
ThreadLocal
<
Gregorian
Calendar
>
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
=
new
ThreadLocal
<>();
/**
...
...
@@ -104,8 +104,8 @@ public class DateTimeUtils {
*
* @return a calendar instance. A cached instance is returned where possible
*/
private
static
Calendar
getCalendar
()
{
Calendar
c
=
CACHED_CALENDAR
.
get
();
private
static
Gregorian
Calendar
getCalendar
()
{
Gregorian
Calendar
c
=
CACHED_CALENDAR
.
get
();
if
(
c
==
null
)
{
c
=
DateTimeUtils
.
createGregorianCalendar
();
CACHED_CALENDAR
.
set
(
c
);
...
...
@@ -120,8 +120,8 @@ public class DateTimeUtils {
* @param tz timezone for the calendar, is never null
* @return a calendar instance. A cached instance is returned where possible
*/
private
static
Calendar
getCalendar
(
TimeZone
tz
)
{
Calendar
c
=
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
.
get
();
private
static
Gregorian
Calendar
getCalendar
(
TimeZone
tz
)
{
Gregorian
Calendar
c
=
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
.
get
();
if
(
c
==
null
||
!
c
.
getTimeZone
().
equals
(
tz
))
{
c
=
DateTimeUtils
.
createGregorianCalendar
(
tz
);
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
.
set
(
c
);
...
...
@@ -139,7 +139,7 @@ public class DateTimeUtils {
*
* @return a new calendar instance.
*/
public
static
Calendar
createGregorianCalendar
()
{
public
static
Gregorian
Calendar
createGregorianCalendar
()
{
return
new
GregorianCalendar
();
}
...
...
@@ -153,7 +153,7 @@ public class DateTimeUtils {
* @param tz timezone for the calendar, is never null
* @return a new calendar instance.
*/
public
static
Calendar
createGregorianCalendar
(
TimeZone
tz
)
{
public
static
Gregorian
Calendar
createGregorianCalendar
(
TimeZone
tz
)
{
return
new
GregorianCalendar
(
tz
);
}
...
...
@@ -522,9 +522,15 @@ public class DateTimeUtils {
*/
public
static
long
getMillis
(
TimeZone
tz
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
GregorianCalendar
c
;
if
(
tz
==
null
)
{
c
=
getCalendar
();
}
else
{
c
=
getCalendar
(
tz
);
}
c
.
setLenient
(
false
);
try
{
return
getTimeTry
(
false
,
tz
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
return
convertToMillis
(
c
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
catch
(
IllegalArgumentException
e
)
{
// special case: if the time simply doesn't exist because of
// daylight saving time changes, use the lenient version
...
...
@@ -533,12 +539,10 @@ public class DateTimeUtils {
if
(
hour
<
0
||
hour
>
23
)
{
throw
e
;
}
return
getTimeTry
(
true
,
tz
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
else
if
(
message
.
indexOf
(
"DAY_OF_MONTH"
)
>
0
)
{
int
maxDay
;
if
(
month
==
2
)
{
maxDay
=
new
GregorianCalendar
()
.
isLeapYear
(
year
)
?
29
:
28
;
maxDay
=
c
.
isLeapYear
(
year
)
?
29
:
28
;
}
else
{
maxDay
=
30
+
((
month
+
(
month
>
7
?
1
:
0
))
&
1
);
}
...
...
@@ -549,26 +553,11 @@ public class DateTimeUtils {
// using the timezone Brasilia and others,
// for example for 2042-10-12 00:00:00.
hour
+=
6
;
return
getTimeTry
(
true
,
tz
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
else
{
return
getTimeTry
(
true
,
tz
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
}
}
private
static
long
getTimeTry
(
boolean
lenient
,
TimeZone
tz
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
Calendar
c
;
if
(
tz
==
null
)
{
c
=
getCalendar
();
}
else
{
c
=
getCalendar
(
tz
);
}
c
.
setLenient
(
lenient
);
c
.
setLenient
(
true
);
return
convertToMillis
(
c
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
}
private
static
long
convertToMillis
(
Calendar
cal
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论