Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c02a9ca8
提交
c02a9ca8
authored
3月 14, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move some methods from DateTimeUtils to DateTimeFunctions
上级
3e4566aa
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
74 行增加
和
70 行删除
+74
-70
Function.java
h2/src/main/org/h2/expression/Function.java
+2
-2
DateTimeFunctions.java
h2/src/main/org/h2/util/DateTimeFunctions.java
+68
-0
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+0
-64
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+4
-4
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
c02a9ca8
...
@@ -1458,7 +1458,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1458,7 +1458,7 @@ public class Function extends Expression implements FunctionCall {
tz
=
DateTimeUtils
.
timeZoneNameFromOffsetMins
(
tz
=
DateTimeUtils
.
timeZoneNameFromOffsetMins
(
((
ValueTimestampTimeZone
)
v0
).
getTimeZoneOffsetMins
());
((
ValueTimestampTimeZone
)
v0
).
getTimeZoneOffsetMins
());
}
}
result
=
ValueString
.
get
(
DateTime
Util
s
.
formatDateTime
(
result
=
ValueString
.
get
(
DateTime
Function
s
.
formatDateTime
(
v0
.
getTimestamp
(),
v1
.
getString
(),
locale
,
tz
),
v0
.
getTimestamp
(),
v1
.
getString
(),
locale
,
tz
),
database
.
getMode
().
treatEmptyStringsAsNull
);
database
.
getMode
().
treatEmptyStringsAsNull
);
}
}
...
@@ -1472,7 +1472,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1472,7 +1472,7 @@ public class Function extends Expression implements FunctionCall {
null
:
v2
==
ValueNull
.
INSTANCE
?
null
:
v2
.
getString
();
null
:
v2
==
ValueNull
.
INSTANCE
?
null
:
v2
.
getString
();
String
tz
=
v3
==
null
?
String
tz
=
v3
==
null
?
null
:
v3
==
ValueNull
.
INSTANCE
?
null
:
v3
.
getString
();
null
:
v3
==
ValueNull
.
INSTANCE
?
null
:
v3
.
getString
();
java
.
util
.
Date
d
=
DateTime
Util
s
.
parseDateTime
(
java
.
util
.
Date
d
=
DateTime
Function
s
.
parseDateTime
(
v0
.
getString
(),
v1
.
getString
(),
locale
,
tz
);
v0
.
getString
(),
v1
.
getString
(),
locale
,
tz
);
result
=
ValueTimestamp
.
fromMillis
(
d
.
getTime
());
result
=
ValueTimestamp
.
fromMillis
(
d
.
getTime
());
}
}
...
...
h2/src/main/org/h2/util/DateTimeFunctions.java
浏览文件 @
c02a9ca8
...
@@ -27,10 +27,13 @@ import static org.h2.expression.Function.YEAR;
...
@@ -27,10 +27,13 @@ import static org.h2.expression.Function.YEAR;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.text.DateFormatSymbols
;
import
java.text.DateFormatSymbols
;
import
java.text.SimpleDateFormat
;
import
java.util.GregorianCalendar
;
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
org.h2.api.ErrorCode
;
import
org.h2.expression.Function
;
import
org.h2.expression.Function
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -371,6 +374,46 @@ public final class DateTimeFunctions {
...
@@ -371,6 +374,46 @@ public final class DateTimeFunctions {
return
result
;
return
result
;
}
}
/**
* Formats a date using a format string.
*
* @param date
* the date to format
* @param format
* the format string
* @param locale
* the locale
* @param timeZone
* the timezone
* @return the formatted date
*/
public
static
String
formatDateTime
(
java
.
util
.
Date
date
,
String
format
,
String
locale
,
String
timeZone
)
{
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
synchronized
(
dateFormat
)
{
return
dateFormat
.
format
(
date
);
}
}
private
static
SimpleDateFormat
getDateFormat
(
String
format
,
String
locale
,
String
timeZone
)
{
try
{
// currently, a new instance is create for each call
// however, could cache the last few instances
SimpleDateFormat
df
;
if
(
locale
==
null
)
{
df
=
new
SimpleDateFormat
(
format
);
}
else
{
Locale
l
=
new
Locale
(
locale
);
df
=
new
SimpleDateFormat
(
format
,
l
);
}
if
(
timeZone
!=
null
)
{
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
}
return
df
;
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
ErrorCode
.
PARSE_ERROR_1
,
e
,
format
+
"/"
+
locale
+
"/"
+
timeZone
);
}
}
private
static
int
getDatePart
(
String
part
)
{
private
static
int
getDatePart
(
String
part
)
{
Integer
p
=
DATE_PART
.
get
(
StringUtils
.
toUpperEnglish
(
part
));
Integer
p
=
DATE_PART
.
get
(
StringUtils
.
toUpperEnglish
(
part
));
if
(
p
==
null
)
{
if
(
p
==
null
)
{
...
@@ -474,6 +517,31 @@ public final class DateTimeFunctions {
...
@@ -474,6 +517,31 @@ public final class DateTimeFunctions {
return
DATE_PART
.
containsKey
(
StringUtils
.
toUpperEnglish
(
part
));
return
DATE_PART
.
containsKey
(
StringUtils
.
toUpperEnglish
(
part
));
}
}
/**
* Parses a date using a format string.
*
* @param date
* the date to parse
* @param format
* the parsing format
* @param locale
* the locale
* @param timeZone
* the timeZone
* @return the parsed date
*/
public
static
java
.
util
.
Date
parseDateTime
(
String
date
,
String
format
,
String
locale
,
String
timeZone
)
{
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
try
{
synchronized
(
dateFormat
)
{
return
dateFormat
.
parse
(
date
);
}
}
catch
(
Exception
e
)
{
// ParseException
throw
DbException
.
get
(
ErrorCode
.
PARSE_ERROR_1
,
e
,
date
);
}
}
private
static
long
weekdiff
(
long
absolute1
,
long
absolute2
,
int
firstDayOfWeek
)
{
private
static
long
weekdiff
(
long
absolute1
,
long
absolute2
,
int
firstDayOfWeek
)
{
absolute1
+=
4
-
firstDayOfWeek
;
absolute1
+=
4
-
firstDayOfWeek
;
long
r1
=
absolute1
/
7
;
long
r1
=
absolute1
/
7
;
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
c02a9ca8
...
@@ -9,12 +9,9 @@ package org.h2.util;
...
@@ -9,12 +9,9 @@ package org.h2.util;
import
java.sql.Date
;
import
java.sql.Date
;
import
java.sql.Time
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Mode
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
...
@@ -859,67 +856,6 @@ public class DateTimeUtils {
...
@@ -859,67 +856,6 @@ public class DateTimeUtils {
return
year
;
return
year
;
}
}
/**
* Formats a date using a format string.
*
* @param date the date to format
* @param format the format string
* @param locale the locale
* @param timeZone the timezone
* @return the formatted date
*/
public
static
String
formatDateTime
(
java
.
util
.
Date
date
,
String
format
,
String
locale
,
String
timeZone
)
{
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
synchronized
(
dateFormat
)
{
return
dateFormat
.
format
(
date
);
}
}
/**
* Parses a date using a format string.
*
* @param date the date to parse
* @param format the parsing format
* @param locale the locale
* @param timeZone the timeZone
* @return the parsed date
*/
public
static
java
.
util
.
Date
parseDateTime
(
String
date
,
String
format
,
String
locale
,
String
timeZone
)
{
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
try
{
synchronized
(
dateFormat
)
{
return
dateFormat
.
parse
(
date
);
}
}
catch
(
Exception
e
)
{
// ParseException
throw
DbException
.
get
(
ErrorCode
.
PARSE_ERROR_1
,
e
,
date
);
}
}
private
static
SimpleDateFormat
getDateFormat
(
String
format
,
String
locale
,
String
timeZone
)
{
try
{
// currently, a new instance is create for each call
// however, could cache the last few instances
SimpleDateFormat
df
;
if
(
locale
==
null
)
{
df
=
new
SimpleDateFormat
(
format
);
}
else
{
Locale
l
=
new
Locale
(
locale
);
df
=
new
SimpleDateFormat
(
format
,
l
);
}
if
(
timeZone
!=
null
)
{
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timeZone
));
}
return
df
;
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
ErrorCode
.
PARSE_ERROR_1
,
e
,
format
+
"/"
+
locale
+
"/"
+
timeZone
);
}
}
/**
/**
* Returns number of days in month.
* Returns number of days in month.
*
*
...
...
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
c02a9ca8
...
@@ -13,7 +13,7 @@ import java.util.Random;
...
@@ -13,7 +13,7 @@ import java.util.Random;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.test.utils.AssertThrows
;
import
org.h2.test.utils.AssertThrows
;
import
org.h2.util.DateTime
Util
s
;
import
org.h2.util.DateTime
Function
s
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
/**
/**
...
@@ -85,7 +85,7 @@ public class TestStringUtils extends TestBase {
...
@@ -85,7 +85,7 @@ public class TestStringUtils extends TestBase {
StringUtils
.
xmlText
(
"Rand&Blue"
));
StringUtils
.
xmlText
(
"Rand&Blue"
));
assertEquals
(
"<<[[[]]]>>"
,
assertEquals
(
"<<[[[]]]>>"
,
StringUtils
.
xmlCData
(
"<<[[[]]]>>"
));
StringUtils
.
xmlCData
(
"<<[[[]]]>>"
));
Date
dt
=
DateTime
Util
s
.
parseDateTime
(
Date
dt
=
DateTime
Function
s
.
parseDateTime
(
"2001-02-03 04:05:06 GMT"
,
"2001-02-03 04:05:06 GMT"
,
"yyyy-MM-dd HH:mm:ss z"
,
"en"
,
"GMT"
);
"yyyy-MM-dd HH:mm:ss z"
,
"en"
,
"GMT"
);
String
s
=
StringUtils
.
xmlStartDoc
()
String
s
=
StringUtils
.
xmlStartDoc
()
...
@@ -99,10 +99,10 @@ public class TestStringUtils extends TestBase {
...
@@ -99,10 +99,10 @@ public class TestStringUtils extends TestBase {
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
DateTime
Util
s
.
formatDateTime
(
dt
,
DateTime
Function
s
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
DateTime
Util
s
.
formatDateTime
(
dt
,
DateTime
Function
s
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"item"
,
null
,
+
StringUtils
.
xmlNode
(
"item"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论