Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
00a1b0e2
提交
00a1b0e2
authored
1月 11, 2016
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting
上级
7e8fa541
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
164 行增加
和
91 行删除
+164
-91
ToDateParser.java
h2/src/main/org/h2/util/ToDateParser.java
+10
-6
ToDateTokenizer.java
h2/src/main/org/h2/util/ToDateTokenizer.java
+131
-70
ToDate.java
h2/src/test/org/h2/samples/ToDate.java
+16
-10
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+4
-2
BuildBase.java
h2/src/tools/org/h2/build/BuildBase.java
+3
-3
没有找到文件。
h2/src/main/org/h2/util/ToDateParser.java
浏览文件 @
00a1b0e2
/*
* Copyright 2004-201
6
H2 Group. Multiple-Licensed under the MPL 2.0,
* Copyright 2004-201
4
H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: Daniel Gredler
*/
...
...
@@ -27,7 +27,8 @@ public class ToDateParser {
/**
* @param input the input date with the date-time info
* @param format the format of date-time info
* @param functionName one of [TO_DATE, TO_TIMESTAMP] (both share the same code)
* @param functionName one of [TO_DATE, TO_TIMESTAMP] (both share the same
* code)
*/
private
ToDateParser
(
ConfigParam
functionName
,
String
input
,
String
format
)
{
// reset calendar - default oracle behaviour
...
...
@@ -72,7 +73,8 @@ public class ToDateParser {
private
Timestamp
getResultingTimestamp
()
{
Calendar
cal
=
(
Calendar
)
getResultCalendar
().
clone
();
int
nanosToSet
=
nanos
==
null
?
cal
.
get
(
Calendar
.
MILLISECOND
)
*
1000000
:
nanos
.
intValue
();
int
nanosToSet
=
nanos
==
null
?
cal
.
get
(
Calendar
.
MILLISECOND
)
*
1000000
:
nanos
.
intValue
();
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
Timestamp
ts
=
new
Timestamp
(
cal
.
getTimeInMillis
());
ts
.
setNanos
(
nanosToSet
);
...
...
@@ -114,7 +116,8 @@ public class ToDateParser {
private
static
ToDateParser
parse
(
ToDateParser
p
)
{
while
(
p
.
hasToParseData
())
{
List
<
ToDateTokenizer
.
FormatTokenEnum
>
tokenList
=
ToDateTokenizer
.
FormatTokenEnum
.
getTokensInQuestion
(
p
.
getFormatStr
());
List
<
ToDateTokenizer
.
FormatTokenEnum
>
tokenList
=
ToDateTokenizer
.
FormatTokenEnum
.
getTokensInQuestion
(
p
.
getFormatStr
());
if
(
tokenList
.
isEmpty
())
{
p
.
removeFirstChar
();
continue
;
...
...
@@ -154,7 +157,8 @@ public class ToDateParser {
int
currentFormatPos
=
orgFormatLen
-
formatStr
.
length
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
format
(
"\n %s('%s', '%s')"
,
functionName
,
unmodifiedInputStr
,
unmodifiedFormatStr
));
sb
.
append
(
format
(
"\n %s('%s', '%s')"
,
functionName
,
unmodifiedInputStr
,
unmodifiedFormatStr
));
sb
.
append
(
format
(
"\n %s^%s , %s^ <-- Parsing failed at this point"
,
format
(
"%"
+
(
functionName
.
name
().
length
()
+
currentInputPos
)
+
"s"
,
""
),
restInputLen
<=
0
?
""
:
format
(
"%"
+
restInputLen
+
"s"
,
""
),
...
...
h2/src/main/org/h2/util/ToDateTokenizer.java
浏览文件 @
00a1b0e2
差异被折叠。
点击展开。
h2/src/test/org/h2/samples/ToDate.java
浏览文件 @
00a1b0e2
...
...
@@ -5,17 +5,14 @@
*/
package
org
.
h2
.
samples
;
import
org.h2.tools.DeleteDbFiles
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
org.h2.tools.DeleteDbFiles
;
/**
* A very simple class that shows how to load the driver, create a database,
...
...
@@ -37,11 +34,20 @@ public class ToDate {
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:~/test"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table ToDateTest(id int primary key, start_date datetime, end_date datetime)"
);
stat
.
execute
(
"insert into ToDateTest values(1, TO_DATE('2015-11-13', 'yyyy-MM-DD'), TO_DATE('2015-12-15', 'YYYY-MM-DD'))"
);
stat
.
execute
(
"insert into ToDateTest values(2, TO_DATE('2015-12-12 00:00:00', 'yyyy-MM-DD HH24:MI:ss'), TO_DATE('2015-12-16 15:00:00', 'YYYY-MM-DD HH24:MI:ss'))"
);
stat
.
execute
(
"insert into ToDateTest values(3, TO_DATE('2015-12-12 08:00 A.M.', 'yyyy-MM-DD HH:MI AM'), TO_DATE('2015-12-17 08:00 P.M.', 'YYYY-MM-DD HH:MI AM'))"
);
stat
.
execute
(
"insert into ToDateTest values(4, TO_DATE(substr('2015-12-12 08:00 A.M.', 1, 10), 'yyyy-MM-DD'), TO_DATE('2015-12-17 08:00 P.M.', 'YYYY-MM-DD HH:MI AM'))"
);
stat
.
execute
(
"create table ToDateTest(id int primary key, "
+
"start_date datetime, end_date datetime)"
);
stat
.
execute
(
"insert into ToDateTest values(1, "
+
"TO_DATE('2015-11-13', 'yyyy-MM-DD'), "
+
"TO_DATE('2015-12-15', 'YYYY-MM-DD'))"
);
stat
.
execute
(
"insert into ToDateTest values(2, "
+
"TO_DATE('2015-12-12 00:00:00', 'yyyy-MM-DD HH24:MI:ss'), "
+
"TO_DATE('2015-12-16 15:00:00', 'YYYY-MM-DD HH24:MI:ss'))"
);
stat
.
execute
(
"insert into ToDateTest values(3, "
+
"TO_DATE('2015-12-12 08:00 A.M.', 'yyyy-MM-DD HH:MI AM'), "
+
"TO_DATE('2015-12-17 08:00 P.M.', 'YYYY-MM-DD HH:MI AM'))"
);
stat
.
execute
(
"insert into ToDateTest values(4, "
+
"TO_DATE(substr('2015-12-12 08:00 A.M.', 1, 10), 'yyyy-MM-DD'), "
+
"TO_DATE('2015-12-17 08:00 P.M.', 'YYYY-MM-DD HH:MI AM'))"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from ToDateTest"
);
while
(
rs
.
next
())
{
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
00a1b0e2
...
...
@@ -1337,7 +1337,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
date
,
ToDateParser
.
toDate
(
"979"
,
"YYY"
));
assertEquals
(
date
,
ToDateParser
.
toDate
(
"979"
,
"IYY"
));
// Gregorian calendar does not have a year 0. 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
// Gregorian calendar does not have a year 0.
// 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
date
=
new
SimpleDateFormat
(
"yyy"
).
parse
(
"-99"
);
setMonth
(
date
,
month
);
assertEquals
(
date
,
ToDateParser
.
toDate
(
"0100 BC"
,
"YYYY BC"
));
...
...
@@ -1346,7 +1347,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
date
,
ToDateParser
.
toDate
(
"-0100"
,
"SYYYY"
));
assertEquals
(
date
,
ToDateParser
.
toDate
(
"-0100"
,
"YYYY"
));
// Gregorian calendar does not have a year 0. 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
// Gregorian calendar does not have a year 0.
// 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
date
=
new
SimpleDateFormat
(
"y"
).
parse
(
"0"
);
setMonth
(
date
,
month
);
assertEquals
(
date
,
ToDateParser
.
toDate
(
"01 BC"
,
"YY BC"
));
...
...
h2/src/tools/org/h2/build/BuildBase.java
浏览文件 @
00a1b0e2
...
...
@@ -308,9 +308,9 @@ public class BuildBase {
protected
int
execScript
(
String
script
,
StringList
args
)
{
if
(
isWindows
())
{
// Under windows, we use the "cmd" command interpreter since it will
// search the path for us without us having to hard-code an
extension
//
for the script we want. (Sometimes we don't know if the extension
// will be .bat or .cmd)
// search the path for us without us having to hard-code an
//
extension for the script we want. (Sometimes we don't know if the
//
extension
will be .bat or .cmd)
StringList
newArgs
=
new
StringList
();
newArgs
.
add
(
"/C"
);
newArgs
.
add
(
script
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论