From: PJ Fanning Date: Fri, 6 Aug 2021 18:19:49 +0000 (+0000) Subject: add basic implementation of TIMEVALUE function X-Git-Tag: REL_5_1_0~82 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8959b9f0654085e2c2f9bc0605a32277ab4863a4;p=poi.git add basic implementation of TIMEVALUE function git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892047 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/TimeValue.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/TimeValue.java index 7afc3f0b0a..2bb56e36be 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/TimeValue.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/TimeValue.java @@ -25,7 +25,6 @@ import org.apache.poi.ss.util.DateParser; import java.time.DateTimeException; import java.time.LocalDate; -import java.util.Date; /** * Implementation for the TIMEVALUE() Excel function.

@@ -59,10 +58,12 @@ public class TimeValue extends Fixed1ArgFunction { } try { - return parseTime(dateTimeText); + return parseTimeFromDateTime(dateTimeText); } catch (Exception e) { try { - return parseTime("1/01/2000 " + dateTimeText); + //this could be a time (with no date part) - prepend a dummy date because + //parseTimeFromDateTime needs it + return parseTimeFromDateTime("1/01/2000 " + dateTimeText); } catch (Exception e2) { LocalDate ld = DateParser.parseLocalDate(dateTimeText); //return 0 as this is a pure date with no time element @@ -77,7 +78,7 @@ public class TimeValue extends Fixed1ArgFunction { } } - private NumberEval parseTime(String dateTimeText) throws EvaluationException { + private NumberEval parseTimeFromDateTime(String dateTimeText) throws EvaluationException { double dateTimeValue = DateUtil.parseDateTime(dateTimeText); return new NumberEval(dateTimeValue - DateUtil.getExcelDate(DateParser.parseLocalDate(dateTimeText))); }