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.