Bug 49138

Summary: Unit tests fail in Polish locale.
Product: POI Reporter: Antoni Mylka <antoni.mylka>
Component: POI OverallAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.7-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Patch that fixes the issue for me.

Description Antoni Mylka 2010-04-16 13:18:44 UTC
Created attachment 25312 [details]
Patch that fixes the issue for me.

This issue is about two related things:

1. A bug in PackagePropertiesPart.java, which makes the date properties be extracted wrongly, the extracted java.util.Date instance refers to a different timestamp than the original value in XML. I say the SimpleDateFormat instance that is used to parse the datetime value from XML should have its timezone set to GMT, otherwise the 'Z' from the XML is ignored and the value is interpreted within the current timezone of the machine that runs the test. This is clearly wrong.

2. Some unit tests make certain assumptions about the look of extracted strings. These assumptions are wrong in Poland, and probably in other locales outside the US.

Both of these cause the build to fail for me.

I'm talking about the current trunk, rev 934444

The attached patch fixes the issue for me.

I'm on windows xp with JDK 1.6.0_18 and and 1.7.1
Comment 1 Yegor Kozlov 2010-04-20 08:59:13 UTC
Thanks for the patch. I applied in r935896 with minor tweaks.

(1) PackagePropertiesPart.(get|set)DateValue should work symmetrically. Your code suggests setting time zone only in the setter, I added it in the getter too.

Also, the correct name of the time zone should be UTC, not GMT. The OOXML spec Part 2 refers to the W3C Note "Date and Time Formats", http://www.w3.org/TR/1998/NOTE-datetime-19980827 which says that Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z"). 

(2) TestHSSFDataFormatter.testGetFormattedCellValueHSSFCell() passed in Polish but failed in Russian locale. It turned out that the code should assert the correct form of month (long 'MMMM' or short 'MMM') as in the original Excel format: 

        String fmt = cell.getCellStyle().getDataFormatString();
        //assert the correct month form, as in the original Excel format
        String monthPtrn = fmt.indexOf("mmmm") != -1 ? "MMMM" : "MMM";

        // 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);

I ran tests for the following locales and all of them passed OK:

 -Duser.language=en -Duser.country=US
 -Duser.language=pl -Duser.country=POL
 -Duser.language=ru -Duser.country=RUS
 -Duser.language=de -Duser.country=DE