diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-08-06 18:19:49 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-08-06 18:19:49 +0000 |
commit | 8959b9f0654085e2c2f9bc0605a32277ab4863a4 (patch) | |
tree | 4987eeda9a515af697b88ebb1d68d3bc404cc99b | |
parent | 5bcde4ceaf11507b7216f6c5f3cb02da74d95778 (diff) | |
download | poi-8959b9f0654085e2c2f9bc0605a32277ab4863a4.tar.gz poi-8959b9f0654085e2c2f9bc0605a32277ab4863a4.zip |
add basic implementation of TIMEVALUE function
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892047 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi/src/main/java/org/apache/poi/ss/formula/functions/TimeValue.java | 9 |
1 files changed, 5 insertions, 4 deletions
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.<p> @@ -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))); } |