Bug 53184 - [PATCH] Unify date formatting between FOP and XGC as well as tidying the date format code
Summary: [PATCH] Unify date formatting between FOP and XGC as well as tidying the date...
Status: CLOSED FIXED
Alias: None
Product: XMLGraphicsCommons - Now in Jira
Classification: Unclassified
Component: utilities (show other bugs)
Version: Trunk
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: --
Assignee: XML Graphics Project Mailing List
URL:
Keywords:
Depends on:
Blocks: 53185
  Show dependency tree
 
Reported: 2012-05-03 14:23 UTC by Robert Meyer
Modified: 2012-05-10 08:25 UTC (History)
0 users



Attachments
Date formatting code changes as well as improved coverage of test cases (18.11 KB, patch)
2012-05-03 14:23 UTC, Robert Meyer
Details | Diff
Fix for existing patch code failing on Junit test (17.92 KB, patch)
2012-05-08 15:34 UTC, Robert Meyer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Meyer 2012-05-03 14:23:23 UTC
Created attachment 28717 [details]
Date formatting code changes as well as improved coverage of test cases

Both FOP and XGC projects had an identical method which formatted dates. This patch looks to tidy up this code and have a single utility class which can be used in XGC and referenced by FOP.
Comment 1 Glenn Adams 2012-05-03 15:35:05 UTC
please file an ICLA per [1] and i'll apply the patch; thanks

[1] http://www.apache.org/licenses/icla.txt
Comment 2 Chris Bowditch 2012-05-04 13:15:42 UTC
Hi Robert, Glenn,

ICLA has been received by the Apache Secretary: http://people.apache.org/committer-index.html

Thanks,

Chris
Comment 3 Robert Meyer 2012-05-04 13:22:27 UTC
Hi Glenn, Chris,

I was just about to post the fact I received the e-mail, but Chris just got there before me. Please let me know if there is anything else you need from me.

Best Regards,

Robert Meyer
Comment 4 Glenn Adams 2012-05-04 16:13:22 UTC
(In reply to comment #3)
> Hi Glenn, Chris,
> 
> I was just about to post the fact I received the e-mail, but Chris just got
> there before me. Please let me know if there is anything else you need from
> me.
> 
> Best Regards,
> 
> Robert Meyer

test testDateFormattingISO8601 fails in the second assert below

String s = XMPSchemaAdapter.formatISO8601Date(dt, TimeZone.getTimeZone("GMT"));
assertEquals("2008-02-07T15:11:07Z", s);
assertEquals(dt, DateFormatUtil.parseISO8601Date(s));

with the following output

Testcase: testDateFormattingISO8601 took 0.01 sec
        FAILED
expected:<Thu Feb 07 07:11:07 PST 2008> but was:<Thu Feb 07 15:11:07 PST 2008>
junit.framework.AssertionFailedError: expected:<Thu Feb 07 07:11:07 PST 2008> but was:<Thu Feb 07 15:11:07 PST 2008>
        at org.apache.xmlgraphics.util.DateFormatUtilTestCase.testDateFormattingISO8601(DateFormatUtilTestCase.java:45)

i am running on MacOS X 10.6.8 and my current time zone is -8:00 (US/PDT)
Comment 5 Robert Meyer 2012-05-05 00:28:45 UTC
I am running the build on my home Windows machine and am getting failing tests also, whereas the code was written, compiled and successfully passed the test suite on my work Linux PC. I have spent several hours on it this evening but have failed to identify and resolve the issue. I initially suspected that it was because the date being formatted in the string wasn't including the offset, but am still getting failing tests even with numerous changes and consulting the existing code. I will resume my investigation once I get back in the office which due to the bank holiday will now be Tuesday.
Comment 6 Vincent Hennebert 2012-05-08 09:58:18 UTC
Try changing line 144 of DateFormatUtil.java from:
String dateFormat = (date.contains("Z")) ? "'Z'" : "Z";
to
String dateFormat = (date.contains("Z")) ? "+0000" : "Z";

I suppose that contrary to Linux, Mac and Windows systems assume local time when no time zone information is present in the date to parse.

HTH,
Vincent
Comment 7 Vincent Hennebert 2012-05-08 13:18:44 UTC
(In reply to comment #6)
Sorry, managed to confuse myself. The pattern should always have a "Z" (unquoted), and the date to parse should be modified if it contains a 'Z'. In formatDateToParse:

if (date.contains("Z")) {
    date = date.replace("Z", "+0000");
} else {
    /* the current code */
}

Something like that.

Vincent
Comment 8 Robert Meyer 2012-05-08 15:34:59 UTC
Created attachment 28742 [details]
Fix for existing patch code failing on Junit test

Thanks Vincent. After reading your first comment I came up with a near identical solution to your second comment and have now submitted this against the patch.
Comment 9 Robert Meyer 2012-05-09 09:54:18 UTC
I have now changed the bug state bakc to NEW from NEEDINFO
Comment 10 Glenn Adams 2012-05-09 10:14:28 UTC
patch applied at http://svn.apache.org/viewvc?rev=1336053&view=rev

thanks Robert! please verify and close this bug if satisfied
Comment 11 Glenn Adams 2012-05-09 12:16:11 UTC
(In reply to comment #8)
> Created attachment 28742 [details]
> Fix for existing patch code failing on Junit test
> 
> Thanks Vincent. After reading your first comment I came up with a near
> identical solution to your second comment and have now submitted this
> against the patch.

possible problem: ISO/IEC 32000:2008 Section 7.9.4 (aka PDF 1.7) specifies

A date shall be a text string of the form

(D:YYYYMMDDHHmmSSOHH'mm)

note that there is no delimiter after the mm field of the GMT offset; i notice your code adds a delimiter
Comment 12 Robert Meyer 2012-05-09 13:25:03 UTC
Hi Glenn,

The code I submitted has not changed the output from the existing method as that also included a delimiter after the date:

    //Taken from PDFInfo.java in FOP

    protected String formatDateTime(Date time, TimeZone tz) {
        ...
            sb.append(Integer.toString(offsetMinutes));
            sb.append('\'');
        ...
    }


Reading Luis's comment on the existing patch I put submitted:

"Now, regarding the last ' after minutes, the third edition (1.4) spec says it
should be there while the 3200-1:2008 says it shouldn't... I had never noticed
it until now...."

After talking to Vincent, he suggested that FOP follows PDF specification 1.4, but I am certainly willing to change the patch to meet the latest specification if required.
Comment 13 Pascal Sancho 2012-05-09 13:34:03 UTC
(In reply to comment #12)
> After talking to Vincent, he suggested that FOP follows PDF specification
> 1.4, but I am certainly willing to change the patch to meet the latest
> specification if required.

Note that there is a new option config (see [1]):
  renderer[@mime="application/pdf"]/version

This should be taken into account if format is version dependent.

[1] http://xmlgraphics.apache.org/fop/trunk/configuration.html#pdf-renderer
Comment 14 Robert Meyer 2012-05-09 15:05:03 UTC
> Note that there is a new option config (see [1]):
>   renderer[@mime="application/pdf"]/version
> 
> This should be taken into account if format is version dependent.
> 
> [1] http://xmlgraphics.apache.org/fop/trunk/configuration.html#pdf-renderer

I agree with what you are both saying and it would be beneficial to implement such a change in the future. I will open a new ticket for this as I feel the current patch has fulfilled its original purpose.
Comment 15 Robert Meyer 2012-05-09 15:31:21 UTC
I have verified the code and will now close the issue. A new ticket (53208) been created relating to support for PDF Reference 1.7.
Comment 16 Glenn Adams 2012-05-09 15:36:05 UTC
(In reply to comment #15)
> I have verified the code and will now close the issue. A new ticket (53208)
> been created relating to support for PDF Reference 1.7.

sounds good