Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-598

DateConverter.toCalendar doesn't clear milliseconds field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.8.0-incubator
    • 1.0.0
    • Utilities
    • None

    Description

      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.

      Attachments

        Activity

          People

            jukkaz Jukka Zitting
            nick Nick Burch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: