提交 68f673ad authored 作者: noelgrandin's avatar noelgrandin

Issue 548: TO_CHAR does not format MM and DD correctly when the month or day of…

Issue 548: TO_CHAR does not format MM and DD correctly when the month or day of the month is 1 digit, patch from "the.tucc"
上级 c97ac5ed
......@@ -629,7 +629,7 @@ public class ToChar {
output.append(cal.get(Calendar.DAY_OF_YEAR));
i += 3;
} else if ((cap = containsAt(format, i, "DD")) != null) {
output.append(cal.get(Calendar.DAY_OF_MONTH));
output.append(String.format("%02d",cal.get(Calendar.DAY_OF_MONTH)));
i += 2;
} else if ((cap = containsAt(format, i, "DY")) != null) {
String day = new SimpleDateFormat("EEE").format(ts).toUpperCase();
......@@ -753,7 +753,7 @@ public class ToChar {
output.append(cap.apply(month));
i += 3;
} else if ((cap = containsAt(format, i, "MM")) != null) {
output.append(cal.get(Calendar.MONTH) + 1);
output.append(String.format("%02d",cal.get(Calendar.MONTH) + 1));
i += 2;
} else if ((cap = containsAt(format, i, "RM")) != null) {
int month = cal.get(Calendar.MONTH) + 1;
......
......@@ -1288,6 +1288,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("7979", stat, "SELECT TO_CHAR(X, 'yyfxyy') FROM T");
assertThrows("", stat, "SELECT TO_CHAR(X, 'A') FROM T");
// check a bug we had when the month or day of the month is 1 digit
stat.executeUpdate("TRUNCATE TABLE T");
stat.executeUpdate("INSERT INTO T VALUES (TIMESTAMP '1985-01-01 08:12:34.560')");
assertResult("19850101", stat, "SELECT TO_CHAR(X, 'YYYYMMDD') FROM T");
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论