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

DateConverter needs to work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.2
    • 1.8.3, 2.0.0
    • Utilities
    • None
    • all os and java platforms

    Description

      Most of the tests for org/apache/pdfbox/util/DateConverter.java in src/test/java/org/apache/pdfbox/util/TestDateUtil.java have been commented out. DateConverter was broken.

      The attached patch fixes the problems. Extensive comments document the problems. Here's a copy:

      /* the former version of DateConverter had these bugs:

      • - In toISO8601 the conversion from millis to minutes was with 1000/1000;
      • should have been 1000/60.
      • - PDFBox-402 was not completely implemented. The calendar fields in the
      • POTENTIAL_FORMATS are shared among threads. Hence we must create new
      • SimpleThreadFormats for each test. (Or synchronize somehow).
      • - Some formats with hh did not have an a field. I changed them to HH.
      • these questionable features:
      • - A timezone with neither plus sign nor minus is assumed to be minus.
      • This seems wrong, but I have not changed it.
      • - toCalendar() returned a value in the default Locale.
      • PDF files do not have locales (I think) and even if they do
      • there is no reason to assume the Java default.
      • I have switched to Locale.ENGLISH which was already assumed
      • in the date formats and toString.
      • and these infelicities:
      • - Constants 60 and 1000 appeared.
      • - zeroAppend was not used where applicable.
      • In one case it was inapplicable only because TimeZone.getOffset
      • was suspected of returning a long. It does not.
      • - Manually computed constants were used to in date.substring
      • thus reducing flexibility and maintainability.
      • - The TimeZone name reported by toCalendar was always "Unknown"
      • It is easy enough to compute a name.
      • - Time zones were not accepted with most of the alternate parsing formats.
      • The new code allows a timezone after any format.
        */

      Attachments

        1. DateConverter.java
          34 kB
          Fred Hansen
        2. TestDateUtil.java
          19 kB
          Fred Hansen

        Issue Links

          Activity

            People

              lehmi Andreas Lehmkühler
              zweibieren Fred Hansen
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified