]> source.dussan.org Git - poi.git/commitdiff
[github-488] Round up seconds in CellElapsedFormatter. Thanks to Anthony Schott....
authorPJ Fanning <fanningpj@apache.org>
Mon, 24 Jul 2023 19:59:45 +0000 (19:59 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 24 Jul 2023 19:59:45 +0000 (19:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911254 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java
poi/src/test/java/org/apache/poi/ss/format/TestCellFormat.java

index 43069d2eabe61c0d0c959928879a1181beff31fd..93fc537d12443bb4d8f0a25c4177ac3fc37bf3df 100644 (file)
@@ -59,7 +59,7 @@ public class CellElapsedFormatter extends CellFormatter {
                 val = elapsed / factor;
             else
                 val = elapsed / factor % modBy;
-            if (type == '0')
+            if (type == '0' || type == 's')
                 return Math.round(val);
             else
                 return (long) val;
index 89badeded201cef0d6cc854400290e175c15c54a..d9572117f49016443c85ffc3b30ec092f82cd331 100644 (file)
@@ -1046,4 +1046,11 @@ class TestCellFormat {
                 .map(CellFormatPart.NAMED_COLORS::get)
                 .forEach(Assertions::assertNotNull);
     }
+
+    @Test
+    void testElapsedSecondsRound() {
+        CellFormatPart part = new CellFormatPart("[h]\\h m\\m s\\s");
+        assertNotNull(part);
+        assertEquals("0h 0m 9s", part.apply(0.0001).text);
+    }
 }