poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1597038 - in /poi/trunk: src/java/org/apache/poi/ss/usermodel/DataFormatter.java src/java/org/apache/poi/ss/usermodel/DateUtil.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java test-data/spreadsheet/54034.xlsx
Date Fri, 23 May 2014 09:18:16 GMT
Author: nick
Date: Fri May 23 09:18:16 2014
New Revision: 1597038

URL: http://svn.apache.org/r1597038
Log:
Handle date format strings in an iso8601 style format, with a T in them. Fixes bug #54034

Added:
    poi/trunk/test-data/spreadsheet/54034.xlsx   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=1597038&r1=1597037&r2=1597038&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Fri May 23 09:18:16
2014
@@ -20,8 +20,6 @@
 ==================================================================== */
 package org.apache.poi.ss.usermodel;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.math.RoundingMode;
 import java.text.DateFormatSymbols;
 import java.text.DecimalFormat;
@@ -424,6 +422,7 @@ public class DataFormatter {
         formatStr = formatStr.replaceAll(";@", "");
         formatStr = formatStr.replaceAll("\"/\"", "/"); // "/" is escaped for no reason in:
mm"/"dd"/"yyyy
         formatStr = formatStr.replace("\"\"", "'");	// replace Excel quoting with Java style
quoting
+        formatStr = formatStr.replaceAll("\\\\T","'T'"); // Quote the T is iso8601 style
dates
 
 
         boolean hasAmPm = false;

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java?rev=1597038&r1=1597037&r2=1597038&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java Fri May 23 09:18:16 2014
@@ -56,7 +56,7 @@ public class DateUtil {
     private static final Pattern date_ptrn1 = Pattern.compile("^\\[\\$\\-.*?\\]");
     private static final Pattern date_ptrn2 = Pattern.compile("^\\[[a-zA-Z]+\\]");
     private static final Pattern date_ptrn3a = Pattern.compile("[yYmMdDhHsS]");
-    private static final Pattern date_ptrn3b = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-/,.
:\"\\\\]+0*[ampAMP/]*$");
+    private static final Pattern date_ptrn3b = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-T/,.
:\"\\\\]+0*[ampAMP/]*$");
     //  elapsed time patterns: [h],[m] and [s]
     private static final Pattern date_ptrn4 = Pattern.compile("^\\[([hH]+|[mM]+|[sS]+)\\]");
 
@@ -445,7 +445,7 @@ public class DateUtil {
         }
         
         // If we get here, check it's only made up, in any case, of:
-        //  y m d h s - \ / , . : [ ]
+        //  y m d h s - \ / , . : [ ] T
         // optionally followed by AM/PM
 
         boolean result = date_ptrn3b.matcher(fs).matches();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1597038&r1=1597037&r2=1597038&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Fri May
23 09:18:16 2014
@@ -18,7 +18,13 @@
 package org.apache.poi.xssf.usermodel;
 
 import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -42,7 +48,25 @@ import org.apache.poi.ss.formula.Workboo
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.formula.functions.Function;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.ss.usermodel.Drawing;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.FormulaError;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
@@ -1501,6 +1525,23 @@ public final class TestXSSFBugs extends 
         
         assertThat(firstSave, equalTo(secondSave));
     }
+    
+    /**
+     * ISO-8601 style cell formats with a T in them, eg
+     * cell format of "yyyy-MM-ddTHH:mm:ss"
+     */
+    @Test
+    public void bug54034() throws IOException {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("54034.xlsx");
+        Sheet sheet = wb.getSheet("Sheet1");
+        Row row = sheet.getRow(1);
+        Cell cell = row.getCell(2);
+        assertTrue(DateUtil.isCellDateFormatted(cell));
+        
+        DataFormatter fmt = new DataFormatter();
+        assertEquals("yyyy\\-mm\\-dd\\Thh:mm", cell.getCellStyle().getDataFormatString());
+        assertEquals("2012-08-08T22:59", fmt.formatCellValue(cell));
+    }
 
 
     @Test

Added: poi/trunk/test-data/spreadsheet/54034.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/54034.xlsx?rev=1597038&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/54034.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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


Mime
View raw message