Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5c6935dd
Unverified
提交
5c6935dd
authored
1月 06, 2018
作者:
Noel Grandin
提交者:
GitHub
1月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #711 from ilm-informatique/TestFunctions-Locale
TestFunctions less english dependent
上级
9c97f812
3e29e664
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
28 行删除
+33
-28
ToChar.java
h2/src/main/org/h2/util/ToChar.java
+4
-3
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+29
-25
没有找到文件。
h2/src/main/org/h2/util/ToChar.java
浏览文件 @
5c6935dd
...
...
@@ -17,6 +17,7 @@ import java.util.Currency;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.message.DbException
;
...
...
@@ -653,7 +654,7 @@ public class ToChar {
cal
.
get
(
Calendar
.
DAY_OF_MONTH
)));
i
+=
2
;
}
else
if
((
cap
=
containsAt
(
format
,
i
,
"DY"
))
!=
null
)
{
String
day
=
StringUtils
.
toUpperEnglish
(
new
SimpleDateFormat
(
"EEE"
).
format
(
ts
)
);
String
day
=
new
SimpleDateFormat
(
"EEE"
).
format
(
ts
);
output
.
append
(
cap
.
apply
(
day
));
i
+=
2
;
}
else
if
((
cap
=
containsAt
(
format
,
i
,
"DAY"
))
!=
null
)
{
...
...
@@ -884,7 +885,7 @@ public class ToChar {
}
/** Represents a capitalization / casing strategy. */
private
enum
Capitalization
{
static
public
enum
Capitalization
{
/**
* All letters are uppercased.
...
...
@@ -911,7 +912,7 @@ public class ToChar {
* @return the capitalization / casing strategy which should be used
* when the first and second letters have the specified casing
*/
p
ublic
static
Capitalization
toCapitalization
(
Boolean
up1
,
Boolean
up2
)
{
p
rivate
static
Capitalization
toCapitalization
(
Boolean
up1
,
Boolean
up2
)
{
if
(
up1
==
null
)
{
return
Capitalization
.
CAPITALIZE
;
}
else
if
(
up2
==
null
)
{
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
5c6935dd
...
...
@@ -27,6 +27,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.text.DecimalFormatSymbols
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
...
...
@@ -53,6 +54,7 @@ import org.h2.util.DateTimeUtils;
import
org.h2.util.IOUtils
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ToChar.Capitalization
;
import
org.h2.util.ToDateParser
;
import
org.h2.value.Value
;
...
...
@@ -1484,18 +1486,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
boolean
daylight
=
tz
.
inDaylightTime
(
new
Date
());
String
tzShortName
=
tz
.
getDisplayName
(
daylight
,
TimeZone
.
SHORT
);
String
tzLongName
=
tz
.
getID
();
final
Timestamp
timestamp1979
=
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
);
stat
.
executeUpdate
(
"CREATE TABLE T (X TIMESTAMP(6))"
);
stat
.
executeUpdate
(
"INSERT INTO T VALUES "
+
"(TIMESTAMP '
1979-11-12 08:12:34.560
')"
);
"(TIMESTAMP '
"
+
timestamp1979
.
toString
()+
"
')"
);
stat
.
executeUpdate
(
"CREATE TABLE U (X TIMESTAMP(6))"
);
stat
.
executeUpdate
(
"INSERT INTO U VALUES "
+
"(TIMESTAMP '-100-01-15 14:04:02.120')"
);
assertResult
(
"1979-11-12 08:12:34.56"
,
stat
,
"SELECT X FROM T"
);
assertResult
(
"-100-01-15 14:04:02.12"
,
stat
,
"SELECT X FROM U"
);
String
expected
=
String
.
format
(
"%tb"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
)).
toUpperCase
();
String
expected
=
String
.
format
(
"%tb"
,
timestamp1979
).
toUpperCase
();
assertResult
(
"12-"
+
expected
+
"-79 08.12.34.560000 AM"
,
stat
,
"SELECT TO_CHAR(X) FROM T"
);
assertResult
(
"- / , . ; : text - /"
,
stat
,
...
...
@@ -1544,8 +1546,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"am"
,
stat
,
"SELECT TO_CHAR(X, 'pm') FROM T"
);
assertResult
(
"2"
,
stat
,
"SELECT TO_CHAR(X, 'D') FROM T"
);
assertResult
(
"2"
,
stat
,
"SELECT TO_CHAR(X, 'd') FROM T"
);
expected
=
String
.
format
(
"%tA"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
String
.
format
(
"%tA"
,
timestamp1979
);
expected
=
expected
.
substring
(
0
,
1
).
toUpperCase
()
+
expected
.
substring
(
1
);
String
spaces
=
" "
;
String
first9
=
(
expected
+
spaces
).
substring
(
0
,
9
);
...
...
@@ -1564,18 +1565,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'DdD') FROM T"
);
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'dDD') FROM T"
);
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'ddd') FROM T"
);
expected
=
String
.
format
(
"%1$tA, %1$tB %1$te, %1$tY"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
String
.
format
(
"%1$tA, %1$tB %1$te, %1$tY"
,
timestamp1979
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'DL') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'DS') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'Ds') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'dS') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'ds') FROM T"
);
expected
=
String
.
format
(
"%1$ta"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
String
.
format
(
"%1$ta"
,
timestamp1979
);
assertResult
(
expected
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'DY') FROM T"
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'Dy') FROM T"
);
assertResult
(
Capitalization
.
CAPITALIZE
.
apply
(
expected
)
,
stat
,
"SELECT TO_CHAR(X, 'Dy') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'dy') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'dY') FROM T"
);
assertResult
(
"08:12:34.560000"
,
stat
,
...
...
@@ -1618,8 +1617,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"11"
,
stat
,
"SELECT TO_CHAR(X, 'Mm') FROM T"
);
assertResult
(
"11"
,
stat
,
"SELECT TO_CHAR(X, 'mM') FROM T"
);
assertResult
(
"11"
,
stat
,
"SELECT TO_CHAR(X, 'mm') FROM T"
);
expected
=
String
.
format
(
"%1$tb"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
String
.
format
(
"%1$tb"
,
timestamp1979
);
expected
=
expected
.
substring
(
0
,
1
).
toUpperCase
()
+
expected
.
substring
(
1
);
assertResult
(
expected
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'MON') FROM T"
);
...
...
@@ -1627,16 +1625,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
"SELECT TO_CHAR(X, 'Mon') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'mon') FROM T"
);
expected
=
String
.
format
(
"%1$tB"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
String
.
format
(
"%1$tB"
,
timestamp1979
);
expected
=
(
expected
+
" "
).
substring
(
0
,
9
);
assertResult
(
expected
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'MONTH') FROM T"
);
assertResult
(
expected
,
stat
,
assertResult
(
Capitalization
.
CAPITALIZE
.
apply
(
expected
)
,
stat
,
"SELECT TO_CHAR(X, 'Month') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'month') FROM T"
);
assertResult
(
expected
.
trim
(
),
stat
,
assertResult
(
Capitalization
.
CAPITALIZE
.
apply
(
expected
.
trim
()
),
stat
,
"SELECT TO_CHAR(X, 'fmMonth') FROM T"
);
assertResult
(
"4"
,
stat
,
"SELECT TO_CHAR(X, 'Q') FROM T"
);
assertResult
(
"XI"
,
stat
,
"SELECT TO_CHAR(X, 'RM') FROM T"
);
...
...
@@ -1646,7 +1643,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"1979"
,
stat
,
"SELECT TO_CHAR(X, 'RRRR') FROM T"
);
assertResult
(
"34"
,
stat
,
"SELECT TO_CHAR(X, 'SS') FROM T"
);
assertResult
(
"29554"
,
stat
,
"SELECT TO_CHAR(X, 'SSSSS') FROM T"
);
assertResult
(
"8:12:34 AM"
,
stat
,
"SELECT TO_CHAR(X, 'TS') FROM T"
);
expected
=
new
SimpleDateFormat
(
"h:mm:ss aa"
).
format
(
timestamp1979
);
if
(
Locale
.
getDefault
().
getLanguage
().
equals
(
Locale
.
ENGLISH
.
getLanguage
()))
{
assertEquals
(
"8:12:34 AM"
,
expected
);
}
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'TS') FROM T"
);
assertResult
(
tzLongName
,
stat
,
"SELECT TO_CHAR(X, 'TZR') FROM T"
);
assertResult
(
tzShortName
,
stat
,
"SELECT TO_CHAR(X, 'TZD') FROM T"
);
expected
=
String
.
format
(
"%f"
,
1.1
).
substring
(
1
,
2
);
...
...
@@ -1933,14 +1934,17 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"0.001"
,
stat
,
"select to_char(0.001, 'FM0.099') from dual;"
);
assertResult
(
"0.001"
,
stat
,
"select to_char(0.0012, 'FM0.099') from dual;"
);
assertResult
(
"0.002"
,
stat
,
"select to_char(0.0019, 'FM0.099') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0, 'FM0D099') from dual;"
);
assertResult
(
"0.00"
,
stat
,
"select to_char(0., 'FM0D009') from dual;"
);
assertResult
(
"0."
,
stat
,
"select to_char(0, 'FM0D9') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0.0, 'FM0D099') from dual;"
);
assertResult
(
"0.00"
,
stat
,
"select to_char(0.00, 'FM0D009') from dual;"
);
assertResult
(
"0.00"
,
stat
,
"select to_char(0, 'FM0D009') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0, 'FM0D09') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0, 'FM0D0') from dual;"
);
final
char
decimalSeparator
=
DecimalFormatSymbols
.
getInstance
().
getDecimalSeparator
();
final
String
oneDecimal
=
"0"
+
decimalSeparator
+
"0"
;
final
String
twoDecimals
=
"0"
+
decimalSeparator
+
"00"
;
assertResult
(
oneDecimal
,
stat
,
"select to_char(0, 'FM0D099') from dual;"
);
assertResult
(
twoDecimals
,
stat
,
"select to_char(0., 'FM0D009') from dual;"
);
assertResult
(
"0"
+
decimalSeparator
,
stat
,
"select to_char(0, 'FM0D9') from dual;"
);
assertResult
(
oneDecimal
,
stat
,
"select to_char(0.0, 'FM0D099') from dual;"
);
assertResult
(
twoDecimals
,
stat
,
"select to_char(0.00, 'FM0D009') from dual;"
);
assertResult
(
twoDecimals
,
stat
,
"select to_char(0, 'FM0D009') from dual;"
);
assertResult
(
oneDecimal
,
stat
,
"select to_char(0, 'FM0D09') from dual;"
);
assertResult
(
oneDecimal
,
stat
,
"select to_char(0, 'FM0D0') from dual;"
);
conn
.
close
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论