From c6aa3a1318271b25fe90a34fca3d6f1de0a813fc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 24 Jul 2023 19:59:45 +0000 Subject: [PATCH] [github-488] Round up seconds in CellElapsedFormatter. Thanks to Anthony Schott. This closes #488 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911254 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/format/CellElapsedFormatter.java | 2 +- .../test/java/org/apache/poi/ss/format/TestCellFormat.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java b/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java index 43069d2eab..93fc537d12 100644 --- a/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java +++ b/poi/src/main/java/org/apache/poi/ss/format/CellElapsedFormatter.java @@ -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; diff --git a/poi/src/test/java/org/apache/poi/ss/format/TestCellFormat.java b/poi/src/test/java/org/apache/poi/ss/format/TestCellFormat.java index 89badeded2..d9572117f4 100644 --- a/poi/src/test/java/org/apache/poi/ss/format/TestCellFormat.java +++ b/poi/src/test/java/org/apache/poi/ss/format/TestCellFormat.java @@ -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); + } }