Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ca01805e
提交
ca01805e
authored
8月 15, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more constants to DateTimeUtils
上级
67c38904
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
90 行增加
和
70 行删除
+90
-70
DateTimeFunctions.java
h2/src/main/org/h2/util/DateTimeFunctions.java
+37
-32
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+53
-38
没有找到文件。
h2/src/main/org/h2/util/DateTimeFunctions.java
浏览文件 @
ca01805e
...
...
@@ -27,6 +27,12 @@ import static org.h2.expression.Function.TIMEZONE_HOUR;
import
static
org
.
h2
.
expression
.
Function
.
TIMEZONE_MINUTE
;
import
static
org
.
h2
.
expression
.
Function
.
WEEK
;
import
static
org
.
h2
.
expression
.
Function
.
YEAR
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
MILLIS_PER_DAY
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
NANOS_PER_DAY
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
NANOS_PER_HOUR
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
NANOS_PER_MINUTE
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
NANOS_PER_SECOND
;
import
java.math.BigDecimal
;
import
java.text.DateFormatSymbols
;
import
java.text.SimpleDateFormat
;
...
...
@@ -34,6 +40,7 @@ import java.util.GregorianCalendar;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.expression.Function
;
...
...
@@ -171,14 +178,14 @@ public final class DateTimeFunctions {
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
count
);
return
DateTimeUtils
.
dateTimeToValue
(
v
,
dateValue
,
timeNanos
,
forceTimestamp
);
case
HOUR:
count
*=
3_600_000_000_000L
;
count
*=
NANOS_PER_HOUR
;
break
;
case
MINUTE:
count
*=
60_000_000_000L
;
count
*=
NANOS_PER_MINUTE
;
break
;
case
SECOND:
case
EPOCH:
count
*=
1_000_000_000
;
count
*=
NANOS_PER_SECOND
;
break
;
case
MILLISECOND:
count
*=
1_000_000
;
...
...
@@ -206,14 +213,14 @@ public final class DateTimeFunctions {
forceTimestamp
=
true
;
}
timeNanos
+=
count
;
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
||
timeNanos
<
0
)
{
if
(
timeNanos
>=
NANOS_PER_DAY
||
timeNanos
<
0
)
{
long
d
;
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
d
=
timeNanos
/
DateTimeUtils
.
NANOS_PER_DAY
;
if
(
timeNanos
>=
NANOS_PER_DAY
)
{
d
=
timeNanos
/
NANOS_PER_DAY
;
}
else
{
d
=
(
timeNanos
-
DateTimeUtils
.
NANOS_PER_DAY
+
1
)
/
DateTimeUtils
.
NANOS_PER_DAY
;
d
=
(
timeNanos
-
NANOS_PER_DAY
+
1
)
/
NANOS_PER_DAY
;
}
timeNanos
-=
d
*
DateTimeUtils
.
NANOS_PER_DAY
;
timeNanos
-=
d
*
NANOS_PER_DAY
;
return
DateTimeUtils
.
dateTimeToValue
(
v
,
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
d
),
timeNanos
,
forceTimestamp
);
...
...
@@ -257,21 +264,22 @@ public final class DateTimeFunctions {
long
timeNanos2
=
a2
[
1
];
switch
(
field
)
{
case
NANOSECOND:
return
(
absolute2
-
absolute1
)
*
DateTimeUtils
.
NANOS_PER_DAY
+
(
timeNanos2
-
timeNanos1
);
return
(
absolute2
-
absolute1
)
*
NANOS_PER_DAY
+
(
timeNanos2
-
timeNanos1
);
case
MICROSECOND:
return
(
absolute2
-
absolute1
)
*
(
DateTimeUtils
.
MILLIS_PER_DAY
*
1_000
)
return
(
absolute2
-
absolute1
)
*
(
MILLIS_PER_DAY
*
1_000
)
+
(
timeNanos2
/
1_000
-
timeNanos1
/
1_000
);
case
MILLISECOND:
return
(
absolute2
-
absolute1
)
*
DateTimeUtils
.
MILLIS_PER_DAY
return
(
absolute2
-
absolute1
)
*
MILLIS_PER_DAY
+
(
timeNanos2
/
1_000_000
-
timeNanos1
/
1_000_000
);
case
SECOND:
case
EPOCH:
return
(
absolute2
-
absolute1
)
*
86_400
+
(
timeNanos2
/
1_000_000_000
-
timeNanos1
/
1_000_000_000
);
return
(
absolute2
-
absolute1
)
*
86_400
+
(
timeNanos2
/
NANOS_PER_SECOND
-
timeNanos1
/
NANOS_PER_SECOND
);
case
MINUTE:
return
(
absolute2
-
absolute1
)
*
1_440
+
(
timeNanos2
/
60_000_000_000L
-
timeNanos1
/
60_000_000_000L
);
return
(
absolute2
-
absolute1
)
*
1_440
+
(
timeNanos2
/
NANOS_PER_MINUTE
-
timeNanos1
/
NANOS_PER_MINUTE
);
case
HOUR:
return
(
absolute2
-
absolute1
)
*
24
+
(
timeNanos2
/
3_600_000_000_000L
-
timeNanos1
/
3_600_000_000_000L
);
return
(
absolute2
-
absolute1
)
*
24
+
(
timeNanos2
/
NANOS_PER_HOUR
-
timeNanos1
/
NANOS_PER_HOUR
);
}
// Fake fall-through
// $FALL-THROUGH$
...
...
@@ -348,7 +356,7 @@ public final class DateTimeFunctions {
}
}
else
{
bd
=
new
BigDecimal
(
DateTimeUtils
.
intervalToAbsolute
(
interval
))
.
divide
(
BigDecimal
.
valueOf
(
1_000_000_000L
));
.
divide
(
BigDecimal
.
valueOf
(
NANOS_PER_SECOND
));
}
return
ValueDecimal
.
get
(
bd
);
}
...
...
@@ -359,7 +367,7 @@ public final class DateTimeFunctions {
// We compute the time in nanoseconds and the total number of days.
BigDecimal
timeNanosBigDecimal
=
new
BigDecimal
(
timeNanos
);
BigDecimal
numberOfDays
=
new
BigDecimal
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
));
BigDecimal
nanosSeconds
=
new
BigDecimal
(
1_000_000_000
);
BigDecimal
nanosSeconds
=
new
BigDecimal
(
NANOS_PER_SECOND
);
BigDecimal
secondsPerDay
=
new
BigDecimal
(
DateTimeUtils
.
SECONDS_PER_DAY
);
// Case where the value is of type time e.g. '10:00:00'
...
...
@@ -440,23 +448,20 @@ public final class DateTimeFunctions {
case
SECOND:
long
nanoInSecond
=
1_000_000_000L
;
long
seconds
=
timeNanosRetrieved
/
nanoInSecond
;
timeNanos
=
seconds
*
nanoInSecond
;
long
seconds
=
timeNanosRetrieved
/
NANOS_PER_SECOND
;
timeNanos
=
seconds
*
NANOS_PER_SECOND
;
break
;
case
MINUTE:
long
nanoInMinute
=
60_000_000_000L
;
long
minutes
=
timeNanosRetrieved
/
nanoInMinute
;
timeNanos
=
minutes
*
nanoInMinute
;
long
minutes
=
timeNanosRetrieved
/
NANOS_PER_MINUTE
;
timeNanos
=
minutes
*
NANOS_PER_MINUTE
;
break
;
case
HOUR:
long
nanoInHour
=
3_600_000_000_000L
;
long
hours
=
timeNanosRetrieved
/
nanoInHour
;
timeNanos
=
hours
*
nanoInHour
;
long
hours
=
timeNanosRetrieved
/
NANOS_PER_HOUR
;
timeNanos
=
hours
*
NANOS_PER_HOUR
;
break
;
case
DAY_OF_MONTH:
...
...
@@ -646,7 +651,7 @@ public final class DateTimeFunctions {
v
=
DateTimeUtils
.
minutesFromInterval
(
qualifier
,
negative
,
leading
,
remaining
);
break
;
case
SECOND:
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000_000_000
;
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
NANOS_PER_SECOND
;
break
;
case
MILLISECOND:
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000_000
%
1_000
;
...
...
@@ -655,7 +660,7 @@ public final class DateTimeFunctions {
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000
%
1_000_000
;
break
;
case
NANOSECOND:
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
%
1_000_000_000
;
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
%
NANOS_PER_SECOND
;
break
;
default
:
throw
DbException
.
getUnsupportedException
(
"getDatePart("
+
date
+
", "
+
field
+
')'
);
...
...
@@ -673,17 +678,17 @@ public final class DateTimeFunctions {
case
DAY_OF_MONTH:
return
DateTimeUtils
.
dayFromDateValue
(
dateValue
);
case
HOUR:
return
(
int
)
(
timeNanos
/
3_600_000_000_000L
%
24
);
return
(
int
)
(
timeNanos
/
NANOS_PER_HOUR
%
24
);
case
MINUTE:
return
(
int
)
(
timeNanos
/
60_000_000_000L
%
60
);
return
(
int
)
(
timeNanos
/
NANOS_PER_MINUTE
%
60
);
case
SECOND:
return
(
int
)
(
timeNanos
/
1_000_000_000
%
60
);
return
(
int
)
(
timeNanos
/
NANOS_PER_SECOND
%
60
);
case
MILLISECOND:
return
(
int
)
(
timeNanos
/
1_000_000
%
1_000
);
case
MICROSECOND:
return
(
int
)
(
timeNanos
/
1_000
%
1_000_000
);
case
NANOSECOND:
return
(
int
)
(
timeNanos
%
1_000_000_000
);
return
(
int
)
(
timeNanos
%
NANOS_PER_SECOND
);
case
DAY_OF_YEAR:
return
DateTimeUtils
.
getDayOfYear
(
dateValue
);
case
DAY_OF_WEEK:
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
ca01805e
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论