瀏覽代碼

[bug-65471] fix DataFormatter so it can handle Ts (ISO 8601)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891862 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_1_0
PJ Fanning 2 年之前
父節點
當前提交
82f989991d

+ 2
- 0
poi/src/main/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java 查看文件

@@ -98,6 +98,8 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
t = t.replace("[mm]", String.valueOf(MM_BRACKET_SYMBOL));
t = t.replace("[s]", String.valueOf(S_BRACKET_SYMBOL));
t = t.replace("[ss]", String.valueOf(SS_BRACKET_SYMBOL));
t = t.replace("T", "'T'");
t = t.replace("''T''", "'T'");
t = t.replaceAll("s.000", "s.SSS");
t = t.replaceAll("s.00", "s." + LL_BRACKET_SYMBOL);
t = t.replaceAll("s.0", "s." + L_BRACKET_SYMBOL);

+ 16
- 16
poi/src/test/java/org/apache/poi/ss/formula/functions/TestText.java 查看文件

@@ -123,14 +123,14 @@ final class TestText {
// Again with Java style
formatArg = new StringEval("MMMM dd, yyyy");
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
result = TextFunction.TEXT.evaluate(args, -1, -1);
testResult = new StringEval(november + " 16, 1900");
assertEquals(testResult.toString(), result.toString());

// And Excel style
formatArg = new StringEval("mmmm dd, yyyy");
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
result = TextFunction.TEXT.evaluate(args, -1, -1);
testResult = new StringEval(november + " 16, 1900");
assertEquals(testResult.toString(), result.toString());
} finally {
@@ -138,22 +138,22 @@ final class TestText {
}
}

@Disabled("see https://bz.apache.org/bugzilla/show_bug.cgi?id=65471")
@Test
void testTextWithISODateTimeFormatSecondArg() {
TimeZone userTZ = LocaleUtil.getUserTimeZone();
LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET"));
try {
// Test with Java style M=Month
ValueEval numArg = new NumberEval(321.321);
ValueEval formatArg = new StringEval("yyyy-mm-ddThh:MM:ss");
ValueEval[] args = { numArg, formatArg };
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
ValueEval testResult = new StringEval("1900-11-16T07:42:14");
assertEquals(testResult.toString(), result.toString());
} finally {
LocaleUtil.setUserTimeZone(userTZ);
}
ValueEval numArg = new NumberEval(321.321);
ValueEval formatArg = new StringEval("yyyy-mm-ddThh:MM:ss");
ValueEval[] args = { numArg, formatArg };
ValueEval result = TextFunction.TEXT.evaluate(args, -1, -1);
ValueEval testResult = new StringEval("1900-11-16T07:42:14");
assertEquals(testResult.toString(), result.toString());

// test milliseconds
formatArg = new StringEval("yyyy-mm-ddThh:MM:ss.000");
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, -1);
testResult = new StringEval("16:11:1900 07:42:14.400");
assertEquals(testResult.toString(), result.toString());

}

}

Loading…
取消
儲存