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;
...
@@ -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
.
TIMEZONE_MINUTE
;
import
static
org
.
h2
.
expression
.
Function
.
WEEK
;
import
static
org
.
h2
.
expression
.
Function
.
WEEK
;
import
static
org
.
h2
.
expression
.
Function
.
YEAR
;
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.math.BigDecimal
;
import
java.text.DateFormatSymbols
;
import
java.text.DateFormatSymbols
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -34,6 +40,7 @@ import java.util.GregorianCalendar;
...
@@ -34,6 +40,7 @@ import java.util.GregorianCalendar;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.expression.Function
;
import
org.h2.expression.Function
;
...
@@ -171,14 +178,14 @@ public final class DateTimeFunctions {
...
@@ -171,14 +178,14 @@ public final class DateTimeFunctions {
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
count
);
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
count
);
return
DateTimeUtils
.
dateTimeToValue
(
v
,
dateValue
,
timeNanos
,
forceTimestamp
);
return
DateTimeUtils
.
dateTimeToValue
(
v
,
dateValue
,
timeNanos
,
forceTimestamp
);
case
HOUR:
case
HOUR:
count
*=
3_600_000_000_000L
;
count
*=
NANOS_PER_HOUR
;
break
;
break
;
case
MINUTE:
case
MINUTE:
count
*=
60_000_000_000L
;
count
*=
NANOS_PER_MINUTE
;
break
;
break
;
case
SECOND:
case
SECOND:
case
EPOCH:
case
EPOCH:
count
*=
1_000_000_000
;
count
*=
NANOS_PER_SECOND
;
break
;
break
;
case
MILLISECOND:
case
MILLISECOND:
count
*=
1_000_000
;
count
*=
1_000_000
;
...
@@ -206,14 +213,14 @@ public final class DateTimeFunctions {
...
@@ -206,14 +213,14 @@ public final class DateTimeFunctions {
forceTimestamp
=
true
;
forceTimestamp
=
true
;
}
}
timeNanos
+=
count
;
timeNanos
+=
count
;
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
||
timeNanos
<
0
)
{
if
(
timeNanos
>=
NANOS_PER_DAY
||
timeNanos
<
0
)
{
long
d
;
long
d
;
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
if
(
timeNanos
>=
NANOS_PER_DAY
)
{
d
=
timeNanos
/
DateTimeUtils
.
NANOS_PER_DAY
;
d
=
timeNanos
/
NANOS_PER_DAY
;
}
else
{
}
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
,
return
DateTimeUtils
.
dateTimeToValue
(
v
,
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
d
),
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
d
),
timeNanos
,
forceTimestamp
);
timeNanos
,
forceTimestamp
);
...
@@ -257,21 +264,22 @@ public final class DateTimeFunctions {
...
@@ -257,21 +264,22 @@ public final class DateTimeFunctions {
long
timeNanos2
=
a2
[
1
];
long
timeNanos2
=
a2
[
1
];
switch
(
field
)
{
switch
(
field
)
{
case
NANOSECOND:
case
NANOSECOND:
return
(
absolute2
-
absolute1
)
*
DateTimeUtils
.
NANOS_PER_DAY
+
(
timeNanos2
-
timeNanos1
);
return
(
absolute2
-
absolute1
)
*
NANOS_PER_DAY
+
(
timeNanos2
-
timeNanos1
);
case
MICROSECOND:
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
);
+
(
timeNanos2
/
1_000
-
timeNanos1
/
1_000
);
case
MILLISECOND:
case
MILLISECOND:
return
(
absolute2
-
absolute1
)
*
DateTimeUtils
.
MILLIS_PER_DAY
return
(
absolute2
-
absolute1
)
*
MILLIS_PER_DAY
+
(
timeNanos2
/
1_000_000
-
timeNanos1
/
1_000_000
);
+
(
timeNanos2
/
1_000_000
-
timeNanos1
/
1_000_000
);
case
SECOND:
case
SECOND:
case
EPOCH:
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:
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:
case
HOUR:
return
(
absolute2
-
absolute1
)
*
24
return
(
absolute2
-
absolute1
)
*
24
+
(
timeNanos2
/
NANOS_PER_HOUR
-
timeNanos1
/
NANOS_PER_HOUR
);
+
(
timeNanos2
/
3_600_000_000_000L
-
timeNanos1
/
3_600_000_000_000L
);
}
}
// Fake fall-through
// Fake fall-through
// $FALL-THROUGH$
// $FALL-THROUGH$
...
@@ -348,7 +356,7 @@ public final class DateTimeFunctions {
...
@@ -348,7 +356,7 @@ public final class DateTimeFunctions {
}
}
}
else
{
}
else
{
bd
=
new
BigDecimal
(
DateTimeUtils
.
intervalToAbsolute
(
interval
))
bd
=
new
BigDecimal
(
DateTimeUtils
.
intervalToAbsolute
(
interval
))
.
divide
(
BigDecimal
.
valueOf
(
1_000_000_000L
));
.
divide
(
BigDecimal
.
valueOf
(
NANOS_PER_SECOND
));
}
}
return
ValueDecimal
.
get
(
bd
);
return
ValueDecimal
.
get
(
bd
);
}
}
...
@@ -359,7 +367,7 @@ public final class DateTimeFunctions {
...
@@ -359,7 +367,7 @@ public final class DateTimeFunctions {
// We compute the time in nanoseconds and the total number of days.
// We compute the time in nanoseconds and the total number of days.
BigDecimal
timeNanosBigDecimal
=
new
BigDecimal
(
timeNanos
);
BigDecimal
timeNanosBigDecimal
=
new
BigDecimal
(
timeNanos
);
BigDecimal
numberOfDays
=
new
BigDecimal
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
));
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
);
BigDecimal
secondsPerDay
=
new
BigDecimal
(
DateTimeUtils
.
SECONDS_PER_DAY
);
// Case where the value is of type time e.g. '10:00:00'
// Case where the value is of type time e.g. '10:00:00'
...
@@ -440,23 +448,20 @@ public final class DateTimeFunctions {
...
@@ -440,23 +448,20 @@ public final class DateTimeFunctions {
case
SECOND:
case
SECOND:
long
nanoInSecond
=
1_000_000_000L
;
long
seconds
=
timeNanosRetrieved
/
NANOS_PER_SECOND
;
long
seconds
=
timeNanosRetrieved
/
nanoInSecond
;
timeNanos
=
seconds
*
NANOS_PER_SECOND
;
timeNanos
=
seconds
*
nanoInSecond
;
break
;
break
;
case
MINUTE:
case
MINUTE:
long
nanoInMinute
=
60_000_000_000L
;
long
minutes
=
timeNanosRetrieved
/
NANOS_PER_MINUTE
;
long
minutes
=
timeNanosRetrieved
/
nanoInMinute
;
timeNanos
=
minutes
*
NANOS_PER_MINUTE
;
timeNanos
=
minutes
*
nanoInMinute
;
break
;
break
;
case
HOUR:
case
HOUR:
long
nanoInHour
=
3_600_000_000_000L
;
long
hours
=
timeNanosRetrieved
/
NANOS_PER_HOUR
;
long
hours
=
timeNanosRetrieved
/
nanoInHour
;
timeNanos
=
hours
*
NANOS_PER_HOUR
;
timeNanos
=
hours
*
nanoInHour
;
break
;
break
;
case
DAY_OF_MONTH:
case
DAY_OF_MONTH:
...
@@ -646,7 +651,7 @@ public final class DateTimeFunctions {
...
@@ -646,7 +651,7 @@ public final class DateTimeFunctions {
v
=
DateTimeUtils
.
minutesFromInterval
(
qualifier
,
negative
,
leading
,
remaining
);
v
=
DateTimeUtils
.
minutesFromInterval
(
qualifier
,
negative
,
leading
,
remaining
);
break
;
break
;
case
SECOND:
case
SECOND:
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000_000_000
;
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
NANOS_PER_SECOND
;
break
;
break
;
case
MILLISECOND:
case
MILLISECOND:
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000_000
%
1_000
;
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000_000
%
1_000
;
...
@@ -655,7 +660,7 @@ public final class DateTimeFunctions {
...
@@ -655,7 +660,7 @@ public final class DateTimeFunctions {
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000
%
1_000_000
;
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
/
1_000
%
1_000_000
;
break
;
break
;
case
NANOSECOND:
case
NANOSECOND:
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
%
1_000_000_000
;
v
=
DateTimeUtils
.
nanosFromInterval
(
qualifier
,
negative
,
leading
,
remaining
)
%
NANOS_PER_SECOND
;
break
;
break
;
default
:
default
:
throw
DbException
.
getUnsupportedException
(
"getDatePart("
+
date
+
", "
+
field
+
')'
);
throw
DbException
.
getUnsupportedException
(
"getDatePart("
+
date
+
", "
+
field
+
')'
);
...
@@ -673,17 +678,17 @@ public final class DateTimeFunctions {
...
@@ -673,17 +678,17 @@ public final class DateTimeFunctions {
case
DAY_OF_MONTH:
case
DAY_OF_MONTH:
return
DateTimeUtils
.
dayFromDateValue
(
dateValue
);
return
DateTimeUtils
.
dayFromDateValue
(
dateValue
);
case
HOUR:
case
HOUR:
return
(
int
)
(
timeNanos
/
3_600_000_000_000L
%
24
);
return
(
int
)
(
timeNanos
/
NANOS_PER_HOUR
%
24
);
case
MINUTE:
case
MINUTE:
return
(
int
)
(
timeNanos
/
60_000_000_000L
%
60
);
return
(
int
)
(
timeNanos
/
NANOS_PER_MINUTE
%
60
);
case
SECOND:
case
SECOND:
return
(
int
)
(
timeNanos
/
1_000_000_000
%
60
);
return
(
int
)
(
timeNanos
/
NANOS_PER_SECOND
%
60
);
case
MILLISECOND:
case
MILLISECOND:
return
(
int
)
(
timeNanos
/
1_000_000
%
1_000
);
return
(
int
)
(
timeNanos
/
1_000_000
%
1_000
);
case
MICROSECOND:
case
MICROSECOND:
return
(
int
)
(
timeNanos
/
1_000
%
1_000_000
);
return
(
int
)
(
timeNanos
/
1_000
%
1_000_000
);
case
NANOSECOND:
case
NANOSECOND:
return
(
int
)
(
timeNanos
%
1_000_000_000
);
return
(
int
)
(
timeNanos
%
NANOS_PER_SECOND
);
case
DAY_OF_YEAR:
case
DAY_OF_YEAR:
return
DateTimeUtils
.
getDayOfYear
(
dateValue
);
return
DateTimeUtils
.
getDayOfYear
(
dateValue
);
case
DAY_OF_WEEK:
case
DAY_OF_WEEK:
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
ca01805e
...
@@ -48,6 +48,21 @@ public class DateTimeUtils {
...
@@ -48,6 +48,21 @@ public class DateTimeUtils {
*/
*/
public
static
final
TimeZone
UTC
=
TimeZone
.
getTimeZone
(
"UTC"
);
public
static
final
TimeZone
UTC
=
TimeZone
.
getTimeZone
(
"UTC"
);
/**
* The number of nanoseconds per second.
*/
public
static
final
long
NANOS_PER_SECOND
=
1_000_000_000
;
/**
* The number of nanoseconds per minute.
*/
public
static
final
long
NANOS_PER_MINUTE
=
60
*
NANOS_PER_SECOND
;
/**
* The number of nanoseconds per hour.
*/
public
static
final
long
NANOS_PER_HOUR
=
60
*
NANOS_PER_MINUTE
;
/**
/**
* The number of nanoseconds per day.
* The number of nanoseconds per day.
*/
*/
...
@@ -406,7 +421,7 @@ public class DateTimeUtils {
...
@@ -406,7 +421,7 @@ public class DateTimeUtils {
if
(
timeOfDay
&&
hour
>=
24
)
{
if
(
timeOfDay
&&
hour
>=
24
)
{
throw
new
IllegalArgumentException
(
s
);
throw
new
IllegalArgumentException
(
s
);
}
}
nanos
+=
((((
hour
*
60L
)
+
minute
)
*
60
)
+
second
)
*
1_000_000_000
;
nanos
+=
((((
hour
*
60L
)
+
minute
)
*
60
)
+
second
)
*
NANOS_PER_SECOND
;
return
negative
?
-
nanos
:
nanos
;
return
negative
?
-
nanos
:
nanos
;
}
}
...
@@ -946,7 +961,7 @@ public class DateTimeUtils {
...
@@ -946,7 +961,7 @@ public class DateTimeUtils {
long
timeNanos
)
{
long
timeNanos
)
{
Timestamp
ts
=
new
Timestamp
(
convertDateTimeValueToMillis
(
null
,
dateValue
,
timeNanos
/
1_000_000
));
Timestamp
ts
=
new
Timestamp
(
convertDateTimeValueToMillis
(
null
,
dateValue
,
timeNanos
/
1_000_000
));
// This method expects the complete nanoseconds value including milliseconds
// This method expects the complete nanoseconds value including milliseconds
ts
.
setNanos
((
int
)
(
timeNanos
%
1_000_000_000
));
ts
.
setNanos
((
int
)
(
timeNanos
%
NANOS_PER_SECOND
));
return
ts
;
return
ts
;
}
}
...
@@ -961,7 +976,7 @@ public class DateTimeUtils {
...
@@ -961,7 +976,7 @@ public class DateTimeUtils {
*/
*/
public
static
Timestamp
convertTimestampTimeZoneToTimestamp
(
long
dateValue
,
long
timeNanos
,
short
offsetMins
)
{
public
static
Timestamp
convertTimestampTimeZoneToTimestamp
(
long
dateValue
,
long
timeNanos
,
short
offsetMins
)
{
Timestamp
ts
=
new
Timestamp
(
getMillis
(
dateValue
,
timeNanos
,
offsetMins
));
Timestamp
ts
=
new
Timestamp
(
getMillis
(
dateValue
,
timeNanos
,
offsetMins
));
ts
.
setNanos
((
int
)
(
timeNanos
%
1_000_000_000
));
ts
.
setNanos
((
int
)
(
timeNanos
%
NANOS_PER_SECOND
));
return
ts
;
return
ts
;
}
}
...
@@ -1701,15 +1716,15 @@ public class DateTimeUtils {
...
@@ -1701,15 +1716,15 @@ public class DateTimeUtils {
leading
=
parseIntervalLeading
(
s
,
0
,
space
,
negative
);
leading
=
parseIntervalLeading
(
s
,
0
,
space
,
negative
);
int
colon
=
s
.
indexOf
(
':'
,
space
+
1
);
int
colon
=
s
.
indexOf
(
':'
,
space
+
1
);
if
(
colon
<
0
)
{
if
(
colon
<
0
)
{
remaining
=
parseIntervalRemaining
(
s
,
space
+
1
,
s
.
length
(),
23
)
*
3_600_000_000_000L
;
remaining
=
parseIntervalRemaining
(
s
,
space
+
1
,
s
.
length
(),
23
)
*
NANOS_PER_HOUR
;
}
else
{
}
else
{
int
colon2
=
s
.
indexOf
(
':'
,
colon
+
1
);
int
colon2
=
s
.
indexOf
(
':'
,
colon
+
1
);
if
(
colon2
<
0
)
{
if
(
colon2
<
0
)
{
remaining
=
parseIntervalRemaining
(
s
,
space
+
1
,
colon
,
23
)
*
3_600_000_000_000L
remaining
=
parseIntervalRemaining
(
s
,
space
+
1
,
colon
,
23
)
*
NANOS_PER_HOUR
+
parseIntervalRemaining
(
s
,
colon
+
1
,
s
.
length
(),
59
)
*
60_000_000_000L
;
+
parseIntervalRemaining
(
s
,
colon
+
1
,
s
.
length
(),
59
)
*
NANOS_PER_MINUTE
;
}
else
{
}
else
{
remaining
=
parseIntervalRemaining
(
s
,
space
+
1
,
colon
,
23
)
*
3_600_000_000_000L
remaining
=
parseIntervalRemaining
(
s
,
space
+
1
,
colon
,
23
)
*
NANOS_PER_HOUR
+
parseIntervalRemaining
(
s
,
colon
+
1
,
colon2
,
59
)
*
60_000_000_000L
+
parseIntervalRemaining
(
s
,
colon
+
1
,
colon2
,
59
)
*
NANOS_PER_MINUTE
+
parseIntervalRemainingSeconds
(
s
,
colon2
+
1
);
+
parseIntervalRemainingSeconds
(
s
,
colon2
+
1
);
}
}
}
}
...
@@ -1727,9 +1742,9 @@ public class DateTimeUtils {
...
@@ -1727,9 +1742,9 @@ public class DateTimeUtils {
leading
=
parseIntervalLeading
(
s
,
0
,
colon
,
negative
);
leading
=
parseIntervalLeading
(
s
,
0
,
colon
,
negative
);
int
colon2
=
s
.
indexOf
(
':'
,
colon
+
1
);
int
colon2
=
s
.
indexOf
(
':'
,
colon
+
1
);
if
(
colon2
<
0
)
{
if
(
colon2
<
0
)
{
remaining
=
parseIntervalRemaining
(
s
,
colon
+
1
,
s
.
length
(),
59
)
*
60_000_000_000L
;
remaining
=
parseIntervalRemaining
(
s
,
colon
+
1
,
s
.
length
(),
59
)
*
NANOS_PER_MINUTE
;
}
else
{
}
else
{
remaining
=
parseIntervalRemaining
(
s
,
colon
+
1
,
colon2
,
59
)
*
60_000_000_000L
remaining
=
parseIntervalRemaining
(
s
,
colon
+
1
,
colon2
,
59
)
*
NANOS_PER_MINUTE
+
parseIntervalRemainingSeconds
(
s
,
colon2
+
1
);
+
parseIntervalRemainingSeconds
(
s
,
colon2
+
1
);
}
}
}
}
...
@@ -1811,7 +1826,7 @@ public class DateTimeUtils {
...
@@ -1811,7 +1826,7 @@ public class DateTimeUtils {
if
(
seconds
<
0
||
seconds
>
59
)
{
if
(
seconds
<
0
||
seconds
>
59
)
{
throw
new
IllegalArgumentException
(
s
);
throw
new
IllegalArgumentException
(
s
);
}
}
return
seconds
*
1_000_000_000L
+
nanos
;
return
seconds
*
NANOS_PER_SECOND
+
nanos
;
}
}
/**
/**
...
@@ -1856,8 +1871,8 @@ public class DateTimeUtils {
...
@@ -1856,8 +1871,8 @@ public class DateTimeUtils {
StringUtils
.
appendZeroPadded
(
buff
,
2
,
remaining
%
60
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
remaining
%
60
);
break
;
break
;
case
DAY_TO_SECOND:
{
case
DAY_TO_SECOND:
{
long
nanos
=
remaining
%
60_000_000_000L
;
long
nanos
=
remaining
%
NANOS_PER_MINUTE
;
remaining
/=
60_000_000_000L
;
remaining
/=
NANOS_PER_MINUTE
;
buff
.
append
(
leading
).
append
(
' '
);
buff
.
append
(
leading
).
append
(
' '
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
remaining
/
60
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
remaining
/
60
);
buff
.
append
(
':'
);
buff
.
append
(
':'
);
...
@@ -1872,9 +1887,9 @@ public class DateTimeUtils {
...
@@ -1872,9 +1887,9 @@ public class DateTimeUtils {
break
;
break
;
case
HOUR_TO_SECOND:
case
HOUR_TO_SECOND:
buff
.
append
(
leading
).
append
(
':'
);
buff
.
append
(
leading
).
append
(
':'
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
remaining
/
60_000_000_000L
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
remaining
/
NANOS_PER_MINUTE
);
buff
.
append
(
':'
);
buff
.
append
(
':'
);
appendSecondsWithNanos
(
buff
,
remaining
%
60_000_000_000L
);
appendSecondsWithNanos
(
buff
,
remaining
%
NANOS_PER_MINUTE
);
break
;
break
;
case
MINUTE_TO_SECOND:
case
MINUTE_TO_SECOND:
buff
.
append
(
leading
).
append
(
':'
);
buff
.
append
(
leading
).
append
(
':'
);
...
@@ -1886,8 +1901,8 @@ public class DateTimeUtils {
...
@@ -1886,8 +1901,8 @@ public class DateTimeUtils {
}
}
private
static
void
appendSecondsWithNanos
(
StringBuilder
buff
,
long
nanos
)
{
private
static
void
appendSecondsWithNanos
(
StringBuilder
buff
,
long
nanos
)
{
StringUtils
.
appendZeroPadded
(
buff
,
2
,
nanos
/
1_000_000_000
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
nanos
/
NANOS_PER_SECOND
);
appendNanos
(
buff
,
nanos
%
1_000_000_000
);
appendNanos
(
buff
,
nanos
%
NANOS_PER_SECOND
);
}
}
private
static
void
appendNanos
(
StringBuilder
buff
,
long
nanos
)
{
private
static
void
appendNanos
(
StringBuilder
buff
,
long
nanos
)
{
...
@@ -1937,34 +1952,34 @@ public class DateTimeUtils {
...
@@ -1937,34 +1952,34 @@ public class DateTimeUtils {
r
=
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
NANOS_PER_DAY
));
r
=
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
NANOS_PER_DAY
));
break
;
break
;
case
HOUR:
case
HOUR:
r
=
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
3_600_000_000_000L
));
r
=
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
NANOS_PER_HOUR
));
break
;
break
;
case
MINUTE:
case
MINUTE:
r
=
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
60_000_000_000L
));
r
=
BigInteger
.
valueOf
(
interval
.
getLeading
()).
multiply
(
BigInteger
.
valueOf
(
NANOS_PER_MINUTE
));
break
;
break
;
case
SECOND:
case
SECOND:
r
=
intervalToAbsolute
(
interval
,
1_000_000_000
);
r
=
intervalToAbsolute
(
interval
,
NANOS_PER_SECOND
);
break
;
break
;
case
YEAR_TO_MONTH:
case
YEAR_TO_MONTH:
r
=
intervalToAbsolute
(
interval
,
12
);
r
=
intervalToAbsolute
(
interval
,
12
);
break
;
break
;
case
DAY_TO_HOUR:
case
DAY_TO_HOUR:
r
=
intervalToAbsolute
(
interval
,
24
,
3_600_000_000_000L
);
r
=
intervalToAbsolute
(
interval
,
24
,
NANOS_PER_HOUR
);
break
;
break
;
case
DAY_TO_MINUTE:
case
DAY_TO_MINUTE:
r
=
intervalToAbsolute
(
interval
,
24
*
60
,
60_000_000_000L
);
r
=
intervalToAbsolute
(
interval
,
24
*
60
,
NANOS_PER_MINUTE
);
break
;
break
;
case
DAY_TO_SECOND:
case
DAY_TO_SECOND:
r
=
intervalToAbsolute
(
interval
,
NANOS_PER_DAY
);
r
=
intervalToAbsolute
(
interval
,
NANOS_PER_DAY
);
break
;
break
;
case
HOUR_TO_MINUTE:
case
HOUR_TO_MINUTE:
r
=
intervalToAbsolute
(
interval
,
60
,
60_000_000_000L
);
r
=
intervalToAbsolute
(
interval
,
60
,
NANOS_PER_MINUTE
);
break
;
break
;
case
HOUR_TO_SECOND:
case
HOUR_TO_SECOND:
r
=
intervalToAbsolute
(
interval
,
3_600_000_000_000L
);
r
=
intervalToAbsolute
(
interval
,
NANOS_PER_HOUR
);
break
;
break
;
case
MINUTE_TO_SECOND:
case
MINUTE_TO_SECOND:
r
=
intervalToAbsolute
(
interval
,
60_000_000_000L
);
r
=
intervalToAbsolute
(
interval
,
NANOS_PER_MINUTE
);
break
;
break
;
default
:
default
:
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
...
@@ -2001,26 +2016,26 @@ public class DateTimeUtils {
...
@@ -2001,26 +2016,26 @@ public class DateTimeUtils {
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_DAY
))),
0
);
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_DAY
))),
0
);
case
HOUR:
case
HOUR:
return
ValueInterval
.
from
(
qualifier
,
absolute
.
signum
()
<
0
,
return
ValueInterval
.
from
(
qualifier
,
absolute
.
signum
()
<
0
,
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
3_600_000_000_000L
))),
0
);
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_HOUR
))),
0
);
case
MINUTE:
case
MINUTE:
return
ValueInterval
.
from
(
qualifier
,
absolute
.
signum
()
<
0
,
return
ValueInterval
.
from
(
qualifier
,
absolute
.
signum
()
<
0
,
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
60_000_000_000L
))),
0
);
leadingExact
(
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_MINUTE
))),
0
);
case
SECOND:
case
SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
1_000_000_000
);
return
intervalFromAbsolute
(
qualifier
,
absolute
,
NANOS_PER_SECOND
);
case
YEAR_TO_MONTH:
case
YEAR_TO_MONTH:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
12
);
return
intervalFromAbsolute
(
qualifier
,
absolute
,
12
);
case
DAY_TO_HOUR:
case
DAY_TO_HOUR:
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
3_600_000_000_000L
)),
24
);
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_HOUR
)),
24
);
case
DAY_TO_MINUTE:
case
DAY_TO_MINUTE:
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
60_000_000_000L
)),
24
*
60
);
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_MINUTE
)),
24
*
60
);
case
DAY_TO_SECOND:
case
DAY_TO_SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
NANOS_PER_DAY
);
return
intervalFromAbsolute
(
qualifier
,
absolute
,
NANOS_PER_DAY
);
case
HOUR_TO_MINUTE:
case
HOUR_TO_MINUTE:
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
60_000_000_000L
)),
60
);
return
intervalFromAbsolute
(
qualifier
,
absolute
.
divide
(
BigInteger
.
valueOf
(
NANOS_PER_MINUTE
)),
60
);
case
HOUR_TO_SECOND:
case
HOUR_TO_SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
3_600_000_000_000L
);
return
intervalFromAbsolute
(
qualifier
,
absolute
,
NANOS_PER_HOUR
);
case
MINUTE_TO_SECOND:
case
MINUTE_TO_SECOND:
return
intervalFromAbsolute
(
qualifier
,
absolute
,
60_000_000_000L
);
return
intervalFromAbsolute
(
qualifier
,
absolute
,
NANOS_PER_MINUTE
);
default
:
default
:
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
...
@@ -2142,7 +2157,7 @@ public class DateTimeUtils {
...
@@ -2142,7 +2157,7 @@ public class DateTimeUtils {
v
=
remaining
/
60
;
v
=
remaining
/
60
;
break
;
break
;
case
DAY_TO_SECOND:
case
DAY_TO_SECOND:
v
=
remaining
/
3_600_000_000_000L
;
v
=
remaining
/
NANOS_PER_HOUR
;
break
;
break
;
default
:
default
:
return
0
;
return
0
;
...
@@ -2176,13 +2191,13 @@ public class DateTimeUtils {
...
@@ -2176,13 +2191,13 @@ public class DateTimeUtils {
v
=
remaining
%
60
;
v
=
remaining
%
60
;
break
;
break
;
case
DAY_TO_SECOND:
case
DAY_TO_SECOND:
v
=
remaining
/
60_000_000_000L
%
60
;
v
=
remaining
/
NANOS_PER_MINUTE
%
60
;
break
;
break
;
case
HOUR_TO_MINUTE:
case
HOUR_TO_MINUTE:
v
=
remaining
;
v
=
remaining
;
break
;
break
;
case
HOUR_TO_SECOND:
case
HOUR_TO_SECOND:
v
=
remaining
/
60_000_000_000L
;
v
=
remaining
/
NANOS_PER_MINUTE
;
break
;
break
;
default
:
default
:
return
0
;
return
0
;
...
@@ -2208,11 +2223,11 @@ public class DateTimeUtils {
...
@@ -2208,11 +2223,11 @@ public class DateTimeUtils {
long
v
;
long
v
;
switch
(
qualifier
)
{
switch
(
qualifier
)
{
case
SECOND:
case
SECOND:
v
=
leading
*
1_000_000_000
+
remaining
;
v
=
leading
*
NANOS_PER_SECOND
+
remaining
;
break
;
break
;
case
DAY_TO_SECOND:
case
DAY_TO_SECOND:
case
HOUR_TO_SECOND:
case
HOUR_TO_SECOND:
v
=
remaining
%
60_000_000_000L
;
v
=
remaining
%
NANOS_PER_MINUTE
;
break
;
break
;
case
MINUTE_TO_SECOND:
case
MINUTE_TO_SECOND:
v
=
remaining
;
v
=
remaining
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论