aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2013-02-19 16:28:40 +0000
committerNick Burch <nick@apache.org>2013-02-19 16:28:40 +0000
commit22f30ab168078817aca145c9a3105b9ba5a9db2a (patch)
treec2b8577b9a1bedc22bdf1d7ad9ef875f693da4ea /src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
parentf0ca7d289974c4a59b157a66e4db56386648f77d (diff)
downloadpoi-22f30ab168078817aca145c9a3105b9ba5a9db2a.tar.gz
poi-22f30ab168078817aca145c9a3105b9ba5a9db2a.zip
Fix bug #54579 - Handle milliseconds in date formats eg ss.000
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1447798 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java')
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 8bc4f0f26d..c6233fcf39 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -21,7 +21,9 @@
package org.apache.poi.ss.usermodel;
+import java.text.DateFormat;
import java.util.Calendar;
+import java.util.Date;
import java.util.Locale;
import junit.framework.TestCase;
@@ -489,4 +491,36 @@ public class TestDataFormatter extends TestCase {
fmt = "0 \"dollars and\" .00 \"cents\"";
assertEquals("19 dollars and .99 cents", dfUS.formatRawCellContents(19.99, -1, fmt));
}
+
+ /**
+ * ExcelStyleDateFormatter should work for Milliseconds too
+ */
+ public void testExcelStyleDateFormatterStringOnMillis() {
+ // Test directly with the .000 style
+ DateFormat formatter1 = new ExcelStyleDateFormatter("ss.000");
+
+ assertEquals("00.001", formatter1.format(new Date(1L)));
+ assertEquals("00.010", formatter1.format(new Date(10L)));
+ assertEquals("00.100", formatter1.format(new Date(100L)));
+ assertEquals("01.000", formatter1.format(new Date(1000L)));
+ assertEquals("01.001", formatter1.format(new Date(1001L)));
+ assertEquals("10.000", formatter1.format(new Date(10000L)));
+ assertEquals("10.001", formatter1.format(new Date(10001L)));
+
+ // Test directly with the .SSS style
+ DateFormat formatter2 = new ExcelStyleDateFormatter("ss.SSS");
+
+ assertEquals("00.001", formatter2.format(new Date(1L)));
+ assertEquals("00.010", formatter2.format(new Date(10L)));
+ assertEquals("00.100", formatter2.format(new Date(100L)));
+ assertEquals("01.000", formatter2.format(new Date(1000L)));
+ assertEquals("01.001", formatter2.format(new Date(1001L)));
+ assertEquals("10.000", formatter2.format(new Date(10000L)));
+ assertEquals("10.001", formatter2.format(new Date(10001L)));
+
+
+ // Test via DataFormatter
+ DataFormatter dfUS = new DataFormatter(Locale.US, true);
+ assertEquals("01.010", dfUS.formatRawCellContents(0.0000116898, -1, "ss.000"));
+ }
}