Author: fanningpj
Date: Fri Jun 21 20:25:46 2024
New Revision: 1918501

URL: http://svn.apache.org/viewvc?rev=1918501&view=rev
Log:
[bug-69147] fix issues with text function when input is a datetime in string 
format

Modified:
    
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java
    
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestText.java

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java?rev=1918501&r1=1918500&r2=1918501&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java
 (original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/TextFunction.java
 Fri Jun 21 20:25:46 2024
@@ -31,6 +31,7 @@ import org.apache.poi.ss.formula.eval.St
 import org.apache.poi.ss.formula.eval.StringValueEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.DateUtil;
 
 public abstract class TextFunction implements Function {
     protected static final DataFormatter formatter = new DataFormatter();
@@ -39,6 +40,7 @@ public abstract class TextFunction imple
         ValueEval ve = OperandResolver.getSingleValue(eval, srcRow, srcCol);
         return OperandResolver.coerceValueToString(ve);
     }
+
     protected static int evaluateIntArg(ValueEval arg, int srcCellRow, int 
srcCellCol) throws EvaluationException {
         ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, 
srcCellCol);
         return OperandResolver.coerceValueToInt(ve);
@@ -363,8 +365,14 @@ public abstract class TextFunction imple
                     } else if (valueVe instanceof StringEval) {
                         evaluated = ((StringEval) valueVe).getStringValue();
                         valueDouble = OperandResolver.parseDouble(evaluated);
+                        if (valueDouble == null) {
+                            try {
+                                valueDouble = 
DateUtil.parseDateTime(evaluated);
+                            } catch (Exception ignored) {
+                                valueDouble = null;
+                            }
+                        }
                     }
-
                     if (valueDouble != null) {
                         String format = 
formatPatternValueEval2String(formatVe);
                         evaluated = 
formatter.formatRawCellContents(valueDouble, -1, format);

Modified: 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestText.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestText.java?rev=1918501&r1=1918500&r2=1918501&view=diff
==============================================================================
--- 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestText.java 
(original)
+++ 
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestText.java 
Fri Jun 21 20:25:46 2024
@@ -286,6 +286,13 @@ final class TestText {
         testText(new NumberEval(DateUtil.getExcelDate(ld)), new 
StringEval("MMM"), "Feb");
     }
 
+    @Test
+    void testTextMMMStringInput() {
+        //  https://bz.apache.org/bugzilla/show_bug.cgi?id=67475
+        String dateInput = "02/28/2022";
+        testText(new StringEval(dateInput), new StringEval("MMM"), "Feb");
+    }
+
     private void testText(ValueEval valueArg, ValueEval formatArg, String 
expectedResult) {
         ValueEval[] args = { valueArg, formatArg };
         ValueEval result = TextFunction.TEXT.evaluate(args, -1, -1);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to