Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8998eab6
提交
8998eab6
authored
7 年前
作者:
Stéphane Eintrazi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove useless Math.floor and add block scope
上级
42cda05c
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
50 行删除
+45
-50
DateTimeFunctions.java
h2/src/main/org/h2/util/DateTimeFunctions.java
+45
-50
没有找到文件。
h2/src/main/org/h2/util/DateTimeFunctions.java
浏览文件 @
8998eab6
...
...
@@ -16,6 +16,7 @@ import static org.h2.expression.Function.ISO_DAY_OF_WEEK;
import
static
org
.
h2
.
expression
.
Function
.
ISO_WEEK
;
import
static
org
.
h2
.
expression
.
Function
.
ISO_YEAR
;
import
static
org
.
h2
.
expression
.
Function
.
MICROSECOND
;
import
static
org
.
h2
.
expression
.
Function
.
MILLENNIUM
;
import
static
org
.
h2
.
expression
.
Function
.
MILLISECOND
;
import
static
org
.
h2
.
expression
.
Function
.
MINUTE
;
import
static
org
.
h2
.
expression
.
Function
.
MONTH
;
...
...
@@ -26,7 +27,6 @@ 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
.
expression
.
Function
.
MILLENNIUM
;
import
java.math.BigDecimal
;
import
java.text.DateFormatSymbols
;
import
java.text.SimpleDateFormat
;
...
...
@@ -389,7 +389,7 @@ public final class DateTimeFunctions {
* @return date truncated to 'day'
*/
public
static
Value
truncateDate
(
String
timeUnitStr
,
Value
value
)
{
Value
result
;
int
timeUnit
=
getDatePart
(
timeUnitStr
);
// Retrieve the dateValue and the time in nanoseconds if the date.
...
...
@@ -398,7 +398,7 @@ public final class DateTimeFunctions {
long
timeNanosRetrieved
=
fieldDateAndTime
[
1
];
// Variable used to the time in nanoseconds of the date truncated.
Long
timeNanos
=
null
;
long
timeNanos
;
// Compute the number of time unit in the date, for example, the
// number of time unit 'HOUR' in '15:14:13' is '15'. Then convert the
...
...
@@ -407,42 +407,42 @@ public final class DateTimeFunctions {
case
MICROSECOND:
long
nanoInMicroSecond
=
1_000
l
;
long
nanoInMicroSecond
=
1_000
L
;
long
microseconds
=
timeNanosRetrieved
/
nanoInMicroSecond
;
timeNanos
=
microseconds
*
nanoInMicroSecond
;
break
;
case
MILLISECOND:
long
nanoInMilliSecond
=
1_000_000
l
;
long
nanoInMilliSecond
=
1_000_000
L
;
long
milliseconds
=
timeNanosRetrieved
/
nanoInMilliSecond
;
timeNanos
=
milliseconds
*
nanoInMilliSecond
;
break
;
case
SECOND:
long
nanoInSecond
=
1_000_000_000
l
;
long
nanoInSecond
=
1_000_000_000
L
;
long
seconds
=
timeNanosRetrieved
/
nanoInSecond
;
timeNanos
=
seconds
*
nanoInSecond
;
break
;
case
MINUTE:
long
nanoInMinute
=
60_000_000_000
l
;
long
nanoInMinute
=
60_000_000_000
L
;
long
minutes
=
timeNanosRetrieved
/
nanoInMinute
;
timeNanos
=
minutes
*
nanoInMinute
;
break
;
case
HOUR:
long
nanoInHour
=
3_600_000_000_000
l
;
long
nanoInHour
=
3_600_000_000_000
L
;
long
hours
=
timeNanosRetrieved
/
nanoInHour
;
timeNanos
=
hours
*
nanoInHour
;
break
;
case
DAY_OF_MONTH:
timeNanos
=
0
l
;
timeNanos
=
0
L
;
break
;
case
WEEK:
...
...
@@ -452,77 +452,72 @@ public final class DateTimeFunctions {
if
(
dayOfWeek
!=
1
)
{
dateValue
=
DateTimeUtils
.
dateValueFromAbsoluteDay
(
absoluteDay
-
dayOfWeek
+
1
);
}
timeNanos
=
0
l
;
timeNanos
=
0
L
;
break
;
case
MONTH:
case
MONTH:
{
long
year
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
int
month
=
DateTimeUtils
.
monthFromDateValue
(
dateValue
);
dateValue
=
DateTimeUtils
.
dateValue
(
year
,
month
,
1
);
timeNanos
=
0
l
;
timeNanos
=
0
L
;
break
;
case
QUARTER:
long
yearForQuarter
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
int
monthForQuarter
=
DateTimeUtils
.
monthFromDateValue
(
dateValue
);
// Round the month to lower quarter
if
(
monthForQuarter
>=
10
)
{
monthForQuarter
=
10
;
}
else
if
(
monthForQuarter
>=
7
)
{
monthForQuarter
=
7
;
}
else
if
(
monthForQuarter
>=
4
)
{
monthForQuarter
=
4
;
}
else
{
monthForQuarter
=
1
;
}
case
QUARTER:
{
dateValue
=
DateTimeUtils
.
dateValue
(
yearForQuarter
,
monthForQuarter
,
1
);
timeNanos
=
0
l
;
long
year
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
int
month
=
DateTimeUtils
.
monthFromDateValue
(
dateValue
);
month
=
((
month
-
1
)
/
3
)
*
3
+
1
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
,
month
,
1
);
timeNanos
=
0L
;
break
;
case
YEAR:
}
case
YEAR:
{
long
year
ForYear
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
dateValue
=
DateTimeUtils
.
dateValue
(
year
ForYear
,
1
,
1
);
timeNanos
=
0
l
;
long
year
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
dateValue
=
DateTimeUtils
.
dateValue
(
year
,
1
,
1
);
timeNanos
=
0
L
;
break
;
case
DECADE:
}
case
DECADE:
{
long
year
ForDecade
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
year
ForDecade
=
(
long
)
(
Math
.
floor
(
yearForDecade
/
10
)
*
10
)
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
ForDecade
,
1
,
1
);
timeNanos
=
0
l
;
long
year
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
year
=
(
year
/
10
)
*
10
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
,
1
,
1
);
timeNanos
=
0
L
;
break
;
case
CENTURY:
}
case
CENTURY:
{
long
year
ForCentury
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
year
ForCentury
=
(
long
)
(
Math
.
floor
((
yearForCentury
-
1
)
/
100
)
*
100
)
+
1
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
ForCentury
,
1
,
1
);
timeNanos
=
0
l
;
long
year
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
year
=
((
year
-
1
)
/
100
)
*
100
+
1
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
,
1
,
1
);
timeNanos
=
0
L
;
break
;
case
MILLENNIUM:
}
case
MILLENNIUM:
{
long
year
ForMillennium
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
year
ForMillennium
=
(
long
)
(
Math
.
floor
((
yearForMillennium
-
1
)
/
1000
)
*
1000
)
+
1
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
ForMillennium
,
1
,
1
);
timeNanos
=
0
l
;
long
year
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
year
=
((
year
-
1
)
/
1000
)
*
1000
+
1
;
dateValue
=
DateTimeUtils
.
dateValue
(
year
,
1
,
1
);
timeNanos
=
0
L
;
break
;
}
if
(
timeNanos
==
null
)
{
default
:
// Return an exception in the timeUnit is not recognized
throw
DbException
.
getUnsupportedException
(
timeUnitStr
);
}
Value
result
;
if
(
value
instanceof
ValueTimestampTimeZone
)
{
// Case we create a timestamp with timezone with the dateValue and
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论