Bug 60369 - [PATCH] Month format 'MMMMM' issue with TEXT-formula and Java 8
Summary: [PATCH] Month format 'MMMMM' issue with TEXT-formula and Java 8
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.13-FINAL
Hardware: PC All
: P2 normal with 1 vote (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2016-11-14 12:13 UTC by Patrick Metz
Modified: 2016-12-30 22:21 UTC (History)
0 users



Attachments
sample file with TEXT-formula (9.16 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2016-11-14 12:13 UTC, Patrick Metz
Details
Zip-file containing proposed patch for bug 60369, test-class and diff-file. (4.44 KB, application/zip)
2016-11-25 13:36 UTC, Patrick Metz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Metz 2016-11-14 12:13:23 UTC
Created attachment 34441 [details]
sample file with TEXT-formula

Hi!

I have an Excel sheet with two columns.
Column A contains a formula and column B date values.

In column A1 there is =TEXT(B1;"MMMMM")
In column A2 there is =TEXT(B2;"MMMMM")
And so on..

When reading the values of column A in POI I will receive a wrong value for dates with march as the month. Instead of getting an 'M' I am getting '• Mär •'. (so 'bullet point' Mär 'bullet point'). My local is German.

I have only seen this behavior when using Java 8, with Java 7 everything seems fine.

Bug?


Regards,
Patrick
Comment 1 Patrick Metz 2016-11-14 14:28:56 UTC
I think we found the place where things go wrong.

It's in the class 'ExcelStyleDateFormatter':

        // Now handle our special cases
        if (s.indexOf(MMMMM_START_SYMBOL) != -1) {
            s = s.replaceAll(
                    MMMMM_START_SYMBOL + "(\\w)\\w+" + MMMMM_TRUNCATE_SYMBOL,
                    "$1"
            );
        }

In Java 8 the short form for 'March' in German is now 'Mär', in Java 7 this was 'Mrz'. So the above regex does not work in this case as there is an Umlaut which is not handled by \w.


Cheers
Patrick
Comment 2 Praveen Siva 2016-11-24 13:10:59 UTC
Hi ,

Is there any update on this ? Is POI support for Java 8 out ?
Comment 3 Javen O'Neal 2016-11-24 20:52:20 UTC
POI works on Java 8: https://builds.apache.org/job/POI-JDK8/

We were busy with the 3.16 beta 1 release, so code changes were limited in the past 2 weeks.
If you have time to put together a unit test that passes on JDK6, JDK7, and JDK8 with your regex fixes, it would be greatly appreciated. See https://poi.apache.org/guidelines.html#Submitting+Patches
Comment 4 Patrick Metz 2016-11-25 13:33:22 UTC
I have added a zip-file containing the patched ExcelStyleDateFormatter, a test class TestExcelStyleDateFormatter and the diff-file for the patch.

I hope everything is in the format it should be, as I was not able to download the read-only svn repository.
Also I am not sure if the test provided would actually belong in some other class, my provided class is a new class in the package org.apache.poi.ss.usermodel.
Comment 5 Patrick Metz 2016-11-25 13:36:45 UTC
Created attachment 34476 [details]
Zip-file containing proposed patch for bug 60369, test-class and diff-file.

This file contains a zip-file with the patched ExcelStyleDateFormatter, a test class TestExcelStyleDateFormatter and the diff-file.
Comment 6 Dominik Stadler 2016-12-30 22:21:30 UTC
Applied via r1776646, thanks for the patch and unit-tests. I slightly adjusted the regex-pattern, the second pipe-symbol seemed unnecessary.