<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">49138 - Fixed locale-sensitive formatters in PackagePropertiesPart</action>
<action dev="POI-DEVELOPERS" type="fix">49153 - Ensure that CTVectorVariant is included in poi-ooxml-schemas.jar</action>
<action dev="POI-DEVELOPERS" type="add">49146 - Added accessors to CoreProperties.Keywords </action>
<action dev="POI-DEVELOPERS" type="fix">48916 - Propagate parent to parent-aware records decoded from Escher</action>
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
}
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = df.parse(s, new ParsePosition(0));
if (d == null) {
throw new InvalidFormatException("Date not well formated");
}
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
return df.format(d.getValue());
}
package org.apache.poi;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.*;
import junit.framework.TestCase;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
-import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties;
+import org.apache.poi.openxml4j.util.Nullable;
/**
* Test setting extended and custom OOXML properties
_coreProperties.setContentStatus(contentStatus);
assertEquals("Draft", contentStatus);
Date created = _coreProperties.getCreated();
- SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM d, ''yy");
- assertEquals("Mon, Jul 20, '09", formatter.format(created));
+ // the original file contains a following value: 2009-07-20T13:12:00Z
+ assertTrue(dateTimeEqualToUTCString(created, "2009-07-20T13:12:00Z"));
String creator = _coreProperties.getCreator();
assertEquals("Paolo Mottadelli", creator);
String subject = _coreProperties.getSubject();
assertEquals("Hello World", title);
}
+ public void testTransitiveSetters() {
+ XWPFDocument doc = new XWPFDocument();
+ CoreProperties cp = doc.getProperties().getCoreProperties();
+
+ Date dateCreated = new GregorianCalendar(2010, 6, 15, 10, 0, 0).getTime();
+ cp.setCreated(new Nullable<Date>(dateCreated));
+ assertEquals(dateCreated.toString(), cp.getCreated().toString());
+
+ doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
+ cp = doc.getProperties().getCoreProperties();
+ Date dt3 = cp.getCreated();
+ assertEquals(dateCreated.toString(), dt3.toString());
+
+ }
+
public void testGetSetRevision() {
String revision = _coreProperties.getRevision();
assertTrue("Revision number is 1", Integer.parseInt(revision) > 1);
_coreProperties.setRevision("20xx");
assertEquals("20", _coreProperties.getRevision());
}
+
+ public static boolean dateTimeEqualToUTCString(Date dateTime, String utcString) {
+ Calendar utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.UK);
+ utcCalendar.setTimeInMillis(dateTime.getTime());
+ String dateTimeUtcString = utcCalendar.get(Calendar.YEAR) + "-" +
+ zeroPad((utcCalendar.get(Calendar.MONTH)+1)) + "-" +
+ zeroPad(utcCalendar.get(Calendar.DAY_OF_MONTH)) + "T" +
+ zeroPad(utcCalendar.get(Calendar.HOUR_OF_DAY)) + ":" +
+ zeroPad(utcCalendar.get(Calendar.MINUTE)) + ":" +
+ zeroPad(utcCalendar.get(Calendar.SECOND)) + "Z";
+
+
+ return utcString.equals(dateTimeUtcString);
+ }
+
+ private static String zeroPad(long i) {
+ if (i >= 0 && i <=9) {
+ return "0" + i;
+ } else {
+ return String.valueOf(i);
+ }
+ }
}
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.TimeZone;
import junit.framework.TestCase;
OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
0));
private void compareProperties(OPCPackage p) throws InvalidFormatException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
0));
import java.io.FileInputStream;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
import junit.framework.TestCase;
assertEquals(-1, text.indexOf("CC:"));
assertEquals(-1, text.indexOf("BCC:"));
assertContains(text, "Subject: Test the content transformer\n");
- assertContains(text, "Date: Thu, 14 Jun 2007 09:42:55\n");
+ Calendar cal = new GregorianCalendar(2007, 5, 14, 9, 42, 55);
+ SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss");
+ String dateText = f.format(cal.getTime());
+ assertContains(text, "Date: " + dateText + "\n");
assertContains(text, "The quick brown fox jumps over the lazy dog");
}
package org.apache.poi.hssf.usermodel;
+import java.math.BigDecimal;
import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.text.Format;
+import java.text.SimpleDateFormat;
+import java.util.GregorianCalendar;
import java.util.Iterator;
+import java.util.Locale;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.Cell;
log("==== VALID DATE FORMATS ====");
while (it.hasNext()) {
Cell cell = it.next();
- log(formatter.formatCellValue(cell));
+ String fmtval = formatter.formatCellValue(cell);
+ log(fmtval);
// should not be equal to "555.555"
- assertTrue( ! "555.555".equals(formatter.formatCellValue(cell)));
+ assertTrue( ! "555.555".equals(fmtval));
+
+ String fmt = cell.getCellStyle().getDataFormatString();
+ //assert the correct month form, as in the original Excel format
+ String monthPtrn = fmt.indexOf("mmmm") != -1 ? "MMMM" : "MMM";
- // should contain "Jul" in the String
- assertTrue( formatter.formatCellValue(cell).indexOf("Jul") > -1);
+ // this line is intended to compute how "July" would look like in the current locale
+ String jul = new SimpleDateFormat(monthPtrn).format(new GregorianCalendar(2010,6,15).getTime());
+ assertTrue( fmtval.indexOf(jul) > -1);
}
// test number formats
while (it.hasNext()) {
HSSFCell cell = (HSSFCell) it.next();
log(formatter.formatCellValue(cell));
- // should be equal to "1234567890.12345"
- assertEquals("1234567890.12345", formatter.formatCellValue(cell));
+ // should be equal to "1234567890.12345"
+ // in some locales the the decimal delimiter is a comma, not a dot
+ char decimalSeparator = new DecimalFormatSymbols().getDecimalSeparator();
+ assertEquals("1234567890" + decimalSeparator + "12345", formatter.formatCellValue(cell));
}
// test Zip+4 format
// now with a formula evaluator
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
log(formatter.formatCellValue(cell, evaluator) + "\t\t\t (with evaluator)");
- assertEquals("24.50%", formatter.formatCellValue(cell,evaluator));
+ char decimalSeparator = new DecimalFormatSymbols().getDecimalSeparator();
+ assertEquals("24" + decimalSeparator + "50%", formatter.formatCellValue(cell,evaluator));
+
}
/**