Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5f196a7e
提交
5f196a7e
authored
1月 24, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass Value directly to DateTimeUtils.getIso*()
上级
07e507f3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
16 行增加
和
35 行删除
+16
-35
Function.java
h2/src/main/org/h2/expression/Function.java
+3
-3
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+9
-6
TestDateIso8601.java
h2/src/test/org/h2/test/unit/TestDateIso8601.java
+4
-26
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
5f196a7e
...
...
@@ -884,13 +884,13 @@ public class Function extends Expression implements FunctionCall {
Calendar
.
YEAR
));
break
;
case
ISO_YEAR:
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoYear
(
v0
.
getDate
()
));
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoYear
(
v0
));
break
;
case
ISO_WEEK:
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoWeek
(
v0
.
getDate
()
));
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoWeek
(
v0
));
break
;
case
ISO_DAY_OF_WEEK:
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoDayOfWeek
(
v0
.
getDate
()
));
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoDayOfWeek
(
v0
));
break
;
case
CURDATE:
case
CURRENT_DATE:
{
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
5f196a7e
...
...
@@ -552,10 +552,11 @@ public class DateTimeUtils {
* starts at Monday. See also http://en.wikipedia.org/wiki/ISO_8601
*
* @author Robert Rathsack
* @param
dat
e the date object which day of week should be calculated
* @param
valu
e the date object which day of week should be calculated
* @return the day of the week, Monday as 1 to Sunday as 7
*/
public
static
int
getIsoDayOfWeek
(
java
.
util
.
Date
date
)
{
public
static
int
getIsoDayOfWeek
(
Value
value
)
{
java
.
util
.
Date
date
=
value
.
getDate
();
Calendar
cal
=
DateTimeUtils
.
createGregorianCalendar
();
cal
.
setTimeInMillis
(
date
.
getTime
());
int
val
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
...
...
@@ -573,10 +574,11 @@ public class DateTimeUtils {
* the December 28th always belongs to the last week.
*
* @author Robert Rathsack
* @param
dat
e the date object which week of year should be calculated
* @param
valu
e the date object which week of year should be calculated
* @return the week of the year
*/
public
static
int
getIsoWeek
(
java
.
util
.
Date
date
)
{
public
static
int
getIsoWeek
(
Value
value
)
{
java
.
util
.
Date
date
=
value
.
getDate
();
Calendar
c
=
DateTimeUtils
.
createGregorianCalendar
();
c
.
setTimeInMillis
(
date
.
getTime
());
c
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
...
...
@@ -588,10 +590,11 @@ public class DateTimeUtils {
* Returns the year according to the ISO week definition.
*
* @author Robert Rathsack
* @param
dat
e the date object which year should be calculated
* @param
valu
e the date object which year should be calculated
* @return the year
*/
public
static
int
getIsoYear
(
java
.
util
.
Date
date
)
{
public
static
int
getIsoYear
(
Value
value
)
{
java
.
util
.
Date
date
=
value
.
getDate
();
Calendar
cal
=
DateTimeUtils
.
createGregorianCalendar
();
cal
.
setTimeInMillis
(
date
.
getTime
());
cal
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
...
...
h2/src/test/org/h2/test/unit/TestDateIso8601.java
浏览文件 @
5f196a7e
...
...
@@ -5,22 +5,18 @@
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Dat
e
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
getIsoDayOfWeek
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
getIsoWeek
;
import
static
org
.
h2
.
util
.
DateTimeUtils
.
getIsoYear
;
import
static
org
.
h2
.
value
.
ValueDate
.
pars
e
;
import
org.h2.test.TestBase
;
import
org.h2.util.DateTimeUtils
;
/**
* Test cases for DateTimeIso8601Utils.
*/
public
class
TestDateIso8601
extends
TestBase
{
private
final
SimpleDateFormat
dateFormatter
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
/**
* Run just this test.
*
...
...
@@ -49,14 +45,6 @@ public class TestDateIso8601 extends TestBase {
testIsoYearJanuary1thSunday
();
}
private
Date
parse
(
String
s
)
throws
ParseException
{
return
dateFormatter
.
parse
(
s
);
}
private
static
int
getIsoDayOfWeek
(
Date
date
)
{
return
DateTimeUtils
.
getIsoDayOfWeek
(
date
);
}
/**
* Test if day of week is returned as Monday = 1 to Sunday = 7.
*/
...
...
@@ -70,11 +58,6 @@ public class TestDateIso8601 extends TestBase {
assertEquals
(
7
,
getIsoDayOfWeek
(
parse
(
"2008-10-05"
)));
}
private
static
int
getIsoWeek
(
Date
date
)
{
Timestamp
ts
=
new
Timestamp
(
date
.
getTime
());
return
DateTimeUtils
.
getIsoWeek
(
ts
);
}
/**
* January 1st is a Monday therefore the week belongs to the next year.
*/
...
...
@@ -154,11 +137,6 @@ public class TestDateIso8601 extends TestBase {
assertEquals
(
2
,
getIsoWeek
(
parse
(
"2012-01-09"
)));
}
private
static
int
getIsoYear
(
Date
date
)
{
Timestamp
ts
=
new
Timestamp
(
date
.
getTime
());
return
DateTimeUtils
.
getIsoYear
(
ts
);
}
/**
* January 1st is a Monday therefore year is equal to isoYear.
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论