You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Nick Burch (JIRA)" <ji...@apache.org> on 2010/01/13 18:28:54 UTC

[jira] Created: (PDFBOX-598) DateConverter.toCalendar doesn't clear milliseconds field

DateConverter.toCalendar doesn't clear milliseconds field
---------------------------------------------------------

                 Key: PDFBOX-598
                 URL: https://issues.apache.org/jira/browse/PDFBOX-598
             Project: PDFBox
          Issue Type: Bug
          Components: Utilities
    Affects Versions: 0.8.0-incubator
            Reporter: Nick Burch
            Priority: Minor


I've just discovered that DateConverter.toCalendar(String date) doesn't clear the milliseconds field from the calendar entries it returns. This means that if you turn the calendar object into a String, the return isn't stable, so your unit tests break :(

It looks to me that as the pdf format doesn't store to that level of detail, it should always be zero'd out, rather than being left to hold the milliseconds of the time you make the call.

This snippet is a failing unit test that shows the issue:

    public void testDateConversion() throws Exception {
       Calendar c = DateConverter.toCalendar("D:20050526205258+01'00'");
       assertEquals(2005, c.get(Calendar.YEAR));
       assertEquals(05-1, c.get(Calendar.MONTH));
       assertEquals(26, c.get(Calendar.DAY_OF_MONTH));
       assertEquals(20, c.get(Calendar.HOUR_OF_DAY));
       assertEquals(52, c.get(Calendar.MINUTE));
       assertEquals(58, c.get(Calendar.SECOND));
       assertEquals(0, c.get(Calendar.MILLISECOND));
    }

Adding "retval.set(Calendar.MILLISECOND, 0)" to the bottom of the method ought to fix it I'd think.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (PDFBOX-598) DateConverter.toCalendar doesn't clear milliseconds field

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-598?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved PDFBOX-598.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 1.0.0
         Assignee: Jukka Zitting

Good point! Fixed as suggested in revision 899494. Special thanks for the unit test!

> DateConverter.toCalendar doesn't clear milliseconds field
> ---------------------------------------------------------
>
>                 Key: PDFBOX-598
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-598
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 0.8.0-incubator
>            Reporter: Nick Burch
>            Assignee: Jukka Zitting
>            Priority: Minor
>             Fix For: 1.0.0
>
>
> I've just discovered that DateConverter.toCalendar(String date) doesn't clear the milliseconds field from the calendar entries it returns. This means that if you turn the calendar object into a String, the return isn't stable, so your unit tests break :(
> It looks to me that as the pdf format doesn't store to that level of detail, it should always be zero'd out, rather than being left to hold the milliseconds of the time you make the call.
> This snippet is a failing unit test that shows the issue:
>     public void testDateConversion() throws Exception {
>        Calendar c = DateConverter.toCalendar("D:20050526205258+01'00'");
>        assertEquals(2005, c.get(Calendar.YEAR));
>        assertEquals(05-1, c.get(Calendar.MONTH));
>        assertEquals(26, c.get(Calendar.DAY_OF_MONTH));
>        assertEquals(20, c.get(Calendar.HOUR_OF_DAY));
>        assertEquals(52, c.get(Calendar.MINUTE));
>        assertEquals(58, c.get(Calendar.SECOND));
>        assertEquals(0, c.get(Calendar.MILLISECOND));
>     }
> Adding "retval.set(Calendar.MILLISECOND, 0)" to the bottom of the method ought to fix it I'd think.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.