You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2019/12/09 10:21:30 UTC
[Bug 63994] New: custom date formats with literals not supported
https://bz.apache.org/bugzilla/show_bug.cgi?id=63994
Bug ID: 63994
Summary: custom date formats with literals not supported
Product: POI
Version: unspecified
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: POI Overall
Assignee: dev@poi.apache.org
Reporter: yuqiu1979@gmail.com
Target Milestone: ---
In MS Excel Version 2016, the following format yields the following example
values:
yyyy-mm-ddThh:mm:ss => 2019-12-09T00:00:00
yyyy-mm-dd"T"hh:mm:ss => 2019-12-09T00:00:00
yyyy-mm-dd""T""hh:mm:ss => 2019-12-09T00:00:00
yyyy-mm-dd"""T"""hh:mm:ss => 2019-12-09T00:00:00
yyyy-mm-dd "CUSTOM" => 2019-12-09 CUSTOM
yyyy-mm-dd"Z" => 2019-12-09Z
"yyyy-mm-ddThh:mm:ss" => yyyy-mm-ddThh:mm:ss
"yyyy-mm-dd"T"hh:mm:ss" => yyyy-mm-ddThh:mm:ss
Only the first one works well for POI.
POI does not treat any custom format using double quotes, as date.
I believe the fix should be in DataFormatter.createDateFormat().
Current Codes (trunk version @ 5th Dec 2019, line 478+):
String formatStr = pFormatStr;
formatStr = formatStr.replaceAll("\\\\-","-");
formatStr = formatStr.replaceAll("\\\\,",",");
formatStr = formatStr.replaceAll("\\\\\\.","."); // . is a special
regexp char
formatStr = formatStr.replaceAll("\\\\ "," ");
formatStr = formatStr.replaceAll("\\\\/","/"); // weird: m\\/d\\/yyyy
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
Patched Codes:
String formatStr = pFormatStr;
formatStr = formatStr.replaceAll("\\\\-","-");
formatStr = formatStr.replaceAll("\\\\,",",");
formatStr = formatStr.replaceAll("\\\\\\.","."); // . is a special
regexp char
formatStr = formatStr.replaceAll("\\\\ "," ");
formatStr = formatStr.replaceAll("\\\\/","/"); // weird: m\\/d\\/yyyy
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, change double to single quotes, char for char.
formatStr = formatStr.replaceAll("'+", "'"); // ++ flatten multiple
quotes as a single quote (presume user quoted correctly)
formatStr = formatStr.replaceAll("\\\\T","'T'"); // Quote the T is
iso8601 style dates
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 63994] custom date formats with literals not supported
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63994
--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
https://bz.apache.org/bugzilla/show_bug.cgi?id=65471 fix handles support for
the T literal
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 63994] custom date formats with literals not supported
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63994
yuqiu1979@gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
CC| |yuqiu1979@gmail.com
--- Comment #1 from yuqiu1979@gmail.com ---
The suggested patch is incomplete.
DateUtil.isADateFormat(), would also need to be changed, to ignore literals
within the custom date/time formats.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org