Unverified 提交 621bfd06 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #877 from katzyn/datetime

Reimplement TO_CHAR without a Calendar and fix 12 AM / 12 PM in it
...@@ -1449,7 +1449,8 @@ public class Function extends Expression implements FunctionCall { ...@@ -1449,7 +1449,8 @@ public class Function extends Expression implements FunctionCall {
case Value.TIME: case Value.TIME:
case Value.DATE: case Value.DATE:
case Value.TIMESTAMP: case Value.TIMESTAMP:
result = ValueString.get(ToChar.toChar(v0.getTimestamp(), case Value.TIMESTAMP_TZ:
result = ValueString.get(ToChar.toCharDateTime(v0,
v1 == null ? null : v1.getString(), v1 == null ? null : v1.getString(),
v2 == null ? null : v2.getString()), v2 == null ? null : v2.getString()),
database.getMode().treatEmptyStringsAsNull); database.getMode().treatEmptyStringsAsNull);
......
...@@ -1453,7 +1453,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1453,7 +1453,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("-100-01-15 14:04:02.12", stat, "SELECT X FROM U"); assertResult("-100-01-15 14:04:02.12", stat, "SELECT X FROM U");
String expected = String.format("%tb", timestamp1979).toUpperCase(); String expected = String.format("%tb", timestamp1979).toUpperCase();
expected = stripTrailingPeriod(expected); expected = stripTrailingPeriod(expected);
assertResult("12-" + expected + "-79 08.12.34.560000 AM", stat, assertResult("12-" + expected + "-79 08.12.34.560000000 AM", stat,
"SELECT TO_CHAR(X) FROM T"); "SELECT TO_CHAR(X) FROM T");
assertResult("- / , . ; : text - /", stat, assertResult("- / , . ; : text - /", stat,
"SELECT TO_CHAR(X, '- / , . ; : \"text\" - /') FROM T"); "SELECT TO_CHAR(X, '- / , . ; : \"text\" - /') FROM T");
...@@ -1492,6 +1492,8 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1492,6 +1492,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("08:12 AM", stat, "SELECT TO_CHAR(X, 'HH:MI PM') FROM T"); assertResult("08:12 AM", stat, "SELECT TO_CHAR(X, 'HH:MI PM') FROM T");
assertResult("02:04 PM", stat, "SELECT TO_CHAR(X, 'HH:MI PM') FROM U"); assertResult("02:04 PM", stat, "SELECT TO_CHAR(X, 'HH:MI PM') FROM U");
assertResult("08:12 A.M.", stat, "SELECT TO_CHAR(X, 'HH:MI P.M.') FROM T"); assertResult("08:12 A.M.", stat, "SELECT TO_CHAR(X, 'HH:MI P.M.') FROM T");
assertResult("12 PM", stat, "SELECT TO_CHAR(TIME '12:00:00', 'HH AM')");
assertResult("12 AM", stat, "SELECT TO_CHAR(TIME '00:00:00', 'HH AM')");
assertResult("A.M.", stat, "SELECT TO_CHAR(X, 'P.M.') FROM T"); assertResult("A.M.", stat, "SELECT TO_CHAR(X, 'P.M.') FROM T");
assertResult("a.m.", stat, "SELECT TO_CHAR(X, 'p.M.') FROM T"); assertResult("a.m.", stat, "SELECT TO_CHAR(X, 'p.M.') FROM T");
assertResult("a.m.", stat, "SELECT TO_CHAR(X, 'p.m.') FROM T"); assertResult("a.m.", stat, "SELECT TO_CHAR(X, 'p.m.') FROM T");
...@@ -1532,7 +1534,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1532,7 +1534,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult(Capitalization.CAPITALIZE.apply(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(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, assertResult("08:12:34.560000000", stat,
"SELECT TO_CHAR(X, 'HH:MI:SS.FF') FROM T"); "SELECT TO_CHAR(X, 'HH:MI:SS.FF') FROM T");
assertResult("08:12:34.5", stat, assertResult("08:12:34.5", stat,
"SELECT TO_CHAR(X, 'HH:MI:SS.FF1') FROM T"); "SELECT TO_CHAR(X, 'HH:MI:SS.FF1') FROM T");
...@@ -1552,10 +1554,10 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1552,10 +1554,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
"SELECT TO_CHAR(X, 'HH:MI:SS.FF8') FROM T"); "SELECT TO_CHAR(X, 'HH:MI:SS.FF8') FROM T");
assertResult("08:12:34.560000000", stat, assertResult("08:12:34.560000000", stat,
"SELECT TO_CHAR(X, 'HH:MI:SS.FF9') FROM T"); "SELECT TO_CHAR(X, 'HH:MI:SS.FF9') FROM T");
assertResult("08:12:34.560000000", stat, assertResult("012345678", stat,
"SELECT TO_CHAR(X, 'HH:MI:SS.ff9') FROM T"); "SELECT TO_CHAR(TIME '0:00:00.012345678', 'FF') FROM T");
assertResult("08:12:34.560000000", stat, assertResult("00", stat,
"SELECT TO_CHAR(X, 'HH:MI:SS.fF9') FROM T"); "SELECT TO_CHAR(TIME '0:00:00.000', 'FF2') FROM T");
assertResult("08:12", stat, "SELECT TO_CHAR(X, 'HH:MI') FROM T"); assertResult("08:12", stat, "SELECT TO_CHAR(X, 'HH:MI') FROM T");
assertResult("08:12", stat, "SELECT TO_CHAR(X, 'HH12:MI') FROM T"); assertResult("08:12", stat, "SELECT TO_CHAR(X, 'HH12:MI') FROM T");
assertResult("08:12", stat, "SELECT TO_CHAR(X, 'HH24:MI') FROM T"); assertResult("08:12", stat, "SELECT TO_CHAR(X, 'HH24:MI') FROM T");
...@@ -1903,7 +1905,8 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1903,7 +1905,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
final String twoDecimals = "0" + decimalSeparator + "00"; final String twoDecimals = "0" + decimalSeparator + "00";
assertResult(oneDecimal, stat, "select to_char(0, 'FM0D099') from dual;"); assertResult(oneDecimal, stat, "select to_char(0, 'FM0D099') from dual;");
assertResult(twoDecimals, stat, "select to_char(0., 'FM0D009') from dual;"); assertResult(twoDecimals, stat, "select to_char(0., 'FM0D009') from dual;");
assertResult("0.000000000", stat, "select to_char(0.000000000, 'FM0D999999999') from dual;"); assertResult("0" + decimalSeparator + "000000000",
stat, "select to_char(0.000000000, 'FM0D999999999') from dual;");
assertResult("0" + decimalSeparator, stat, "select to_char(0, 'FM0D9') 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(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.00, 'FM0D009') from dual;");
......
...@@ -43,6 +43,7 @@ public class TestClearReferences extends TestBase { ...@@ -43,6 +43,7 @@ public class TestClearReferences extends TestBase {
"org.h2.util.JdbcUtils.allowedClassNamePrefixes", "org.h2.util.JdbcUtils.allowedClassNamePrefixes",
"org.h2.util.JdbcUtils.userClassFactories", "org.h2.util.JdbcUtils.userClassFactories",
"org.h2.util.Task.counter", "org.h2.util.Task.counter",
"org.h2.util.ToChar.NAMES",
"org.h2.value.CompareMode.lastUsed", "org.h2.value.CompareMode.lastUsed",
"org.h2.value.Value.softCache", "org.h2.value.Value.softCache",
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论