Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b3f66155
Unverified
提交
b3f66155
authored
2月 16, 2018
作者:
Noel Grandin
提交者:
GitHub
2月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #880 from katzyn/datetime
Assorted date-time related changes
上级
794abfc5
63f6a13e
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
31 行增加
和
26 行删除
+31
-26
AggregateDataMedian.java
h2/src/main/org/h2/expression/AggregateDataMedian.java
+2
-1
Function.java
h2/src/main/org/h2/expression/Function.java
+22
-7
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+6
-18
TestClearReferences.java
h2/src/test/org/h2/test/unit/TestClearReferences.java
+1
-0
没有找到文件。
h2/src/main/org/h2/expression/AggregateDataMedian.java
浏览文件 @
b3f66155
...
@@ -224,7 +224,8 @@ class AggregateDataMedian extends AggregateData {
...
@@ -224,7 +224,8 @@ class AggregateDataMedian extends AggregateData {
case
Value
.
DOUBLE
:
case
Value
.
DOUBLE
:
return
ValueDouble
.
get
((
v0
.
getFloat
()
+
v1
.
getDouble
())
/
2
);
return
ValueDouble
.
get
((
v0
.
getFloat
()
+
v1
.
getDouble
())
/
2
);
case
Value
.
TIME
:
{
case
Value
.
TIME
:
{
return
ValueTime
.
fromMillis
((
v0
.
getTime
().
getTime
()
+
v1
.
getTime
().
getTime
())
/
2
);
ValueTime
t0
=
(
ValueTime
)
v0
.
convertTo
(
Value
.
TIME
),
t1
=
(
ValueTime
)
v1
.
convertTo
(
Value
.
TIME
);
return
ValueTime
.
fromNanos
((
t0
.
getNanos
()
+
t1
.
getNanos
())
/
2
);
}
}
case
Value
.
DATE
:
{
case
Value
.
DATE
:
{
ValueDate
d0
=
(
ValueDate
)
v0
.
convertTo
(
Value
.
DATE
),
d1
=
(
ValueDate
)
v1
.
convertTo
(
Value
.
DATE
);
ValueDate
d0
=
(
ValueDate
)
v0
.
convertTo
(
Value
.
DATE
),
d1
=
(
ValueDate
)
v1
.
convertTo
(
Value
.
DATE
);
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
b3f66155
...
@@ -15,7 +15,7 @@ import java.nio.charset.StandardCharsets;
...
@@ -15,7 +15,7 @@ import java.nio.charset.StandardCharsets;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.text.
SimpleDateFormat
;
import
java.text.
DateFormatSymbols
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.GregorianCalendar
;
import
java.util.GregorianCalendar
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -153,6 +153,11 @@ public class Function extends Expression implements FunctionCall {
...
@@ -153,6 +153,11 @@ public class Function extends Expression implements FunctionCall {
private
static
final
HashMap
<
String
,
Integer
>
DATE_PART
=
new
HashMap
<>();
private
static
final
HashMap
<
String
,
Integer
>
DATE_PART
=
new
HashMap
<>();
private
static
final
char
[]
SOUNDEX_INDEX
=
new
char
[
128
];
private
static
final
char
[]
SOUNDEX_INDEX
=
new
char
[
128
];
/**
* English names of months and week days.
*/
private
static
volatile
String
[][]
MONTHS_AND_WEEKS
;
protected
Expression
[]
args
;
protected
Expression
[]
args
;
private
final
FunctionInfo
info
;
private
final
FunctionInfo
info
;
...
@@ -844,9 +849,8 @@ public class Function extends Expression implements FunctionCall {
...
@@ -844,9 +849,8 @@ public class Function extends Expression implements FunctionCall {
database
.
getMode
().
treatEmptyStringsAsNull
);
database
.
getMode
().
treatEmptyStringsAsNull
);
break
;
break
;
case
DAY_NAME:
{
case
DAY_NAME:
{
SimpleDateFormat
dayName
=
new
SimpleDateFormat
(
int
dayOfWeek
=
DateTimeUtils
.
getSundayDayOfWeek
(
DateTimeUtils
.
dateAndTimeFromValue
(
v0
)[
0
]);
"EEEE"
,
Locale
.
ENGLISH
);
result
=
ValueString
.
get
(
getMonthsAndWeeks
(
1
)[
dayOfWeek
],
result
=
ValueString
.
get
(
dayName
.
format
(
v0
.
getDate
()),
database
.
getMode
().
treatEmptyStringsAsNull
);
database
.
getMode
().
treatEmptyStringsAsNull
);
break
;
break
;
}
}
...
@@ -866,9 +870,8 @@ public class Function extends Expression implements FunctionCall {
...
@@ -866,9 +870,8 @@ public class Function extends Expression implements FunctionCall {
result
=
ValueInt
.
get
(
getIntDatePart
(
v0
,
info
.
type
));
result
=
ValueInt
.
get
(
getIntDatePart
(
v0
,
info
.
type
));
break
;
break
;
case
MONTH_NAME:
{
case
MONTH_NAME:
{
SimpleDateFormat
monthName
=
new
SimpleDateFormat
(
"MMMM"
,
int
month
=
DateTimeUtils
.
monthFromDateValue
(
DateTimeUtils
.
dateAndTimeFromValue
(
v0
)[
0
]);
Locale
.
ENGLISH
);
result
=
ValueString
.
get
(
getMonthsAndWeeks
(
0
)[
month
-
1
],
result
=
ValueString
.
get
(
monthName
.
format
(
v0
.
getDate
()),
database
.
getMode
().
treatEmptyStringsAsNull
);
database
.
getMode
().
treatEmptyStringsAsNull
);
break
;
break
;
}
}
...
@@ -2025,6 +2028,18 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2025,6 +2028,18 @@ public class Function extends Expression implements FunctionCall {
return
r2
-
r1
;
return
r2
-
r1
;
}
}
private
static
String
[]
getMonthsAndWeeks
(
int
field
)
{
String
[][]
result
=
MONTHS_AND_WEEKS
;
if
(
result
==
null
)
{
result
=
new
String
[
2
][];
DateFormatSymbols
dfs
=
DateFormatSymbols
.
getInstance
(
Locale
.
ENGLISH
);
result
[
0
]
=
dfs
.
getMonths
();
result
[
1
]
=
dfs
.
getWeekdays
();
MONTHS_AND_WEEKS
=
result
;
}
return
result
[
field
];
}
private
static
String
substring
(
String
s
,
int
start
,
int
length
)
{
private
static
String
substring
(
String
s
,
int
start
,
int
length
)
{
int
len
=
s
.
length
();
int
len
=
s
.
length
();
start
--;
start
--;
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
b3f66155
...
@@ -628,20 +628,6 @@ public class DateTimeUtils {
...
@@ -628,20 +628,6 @@ public class DateTimeUtils {
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
timeNanos
);
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
timeNanos
);
}
}
/**
* Get the year (positive or negative) from a calendar.
*
* @param calendar the calendar
* @return the year
*/
private
static
int
getYear
(
Calendar
calendar
)
{
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
if
(
calendar
.
get
(
Calendar
.
ERA
)
==
GregorianCalendar
.
BC
)
{
year
=
1
-
year
;
}
return
year
;
}
/**
/**
* Get the number of milliseconds since 1970-01-01 in the local timezone,
* Get the number of milliseconds since 1970-01-01 in the local timezone,
* but without daylight saving time into account.
* but without daylight saving time into account.
...
@@ -1069,10 +1055,12 @@ public class DateTimeUtils {
...
@@ -1069,10 +1055,12 @@ public class DateTimeUtils {
* @return the date value
* @return the date value
*/
*/
private
static
long
dateValueFromCalendar
(
Calendar
cal
)
{
private
static
long
dateValueFromCalendar
(
Calendar
cal
)
{
int
year
,
month
,
day
;
int
year
=
cal
.
get
(
Calendar
.
YEAR
);
year
=
getYear
(
cal
);
if
(
cal
.
get
(
Calendar
.
ERA
)
==
GregorianCalendar
.
BC
)
{
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
year
=
1
-
year
;
day
=
cal
.
get
(
Calendar
.
DAY_OF_MONTH
);
}
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
int
day
=
cal
.
get
(
Calendar
.
DAY_OF_MONTH
);
return
((
long
)
year
<<
SHIFT_YEAR
)
|
(
month
<<
SHIFT_MONTH
)
|
day
;
return
((
long
)
year
<<
SHIFT_YEAR
)
|
(
month
<<
SHIFT_MONTH
)
|
day
;
}
}
...
...
h2/src/test/org/h2/test/unit/TestClearReferences.java
浏览文件 @
b3f66155
...
@@ -26,6 +26,7 @@ public class TestClearReferences extends TestBase {
...
@@ -26,6 +26,7 @@ public class TestClearReferences extends TestBase {
"org.h2.compress.CompressLZF.cachedHashTable"
,
"org.h2.compress.CompressLZF.cachedHashTable"
,
"org.h2.engine.DbSettings.defaultSettings"
,
"org.h2.engine.DbSettings.defaultSettings"
,
"org.h2.engine.SessionRemote.sessionFactory"
,
"org.h2.engine.SessionRemote.sessionFactory"
,
"org.h2.expression.Function.MONTHS_AND_WEEKS"
,
"org.h2.jdbcx.JdbcDataSourceFactory.cachedTraceSystem"
,
"org.h2.jdbcx.JdbcDataSourceFactory.cachedTraceSystem"
,
"org.h2.store.RecoverTester.instance"
,
"org.h2.store.RecoverTester.instance"
,
"org.h2.store.fs.FilePath.defaultProvider"
,
"org.h2.store.fs.FilePath.defaultProvider"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论