Commons Lang
  1. Commons Lang
  2. LANG-117

[lang] FastDateFormat: wrong format for date "01.01.1000"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.2
    • Component/s: lang.time.*
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: PC

      Description

      FastDateFromat.getInstance("dd.MM.yyyy").format(date) returns "01.01.01000",
      when date is 1 Januar 1000 (01.01.1000)

        Activity

        Hide
        Henri Yandell added a comment -

        Adding unit test for #39410. Implementing fix by switching from using Math.log
        to Integer.toString to figure out the number of digits.

        Sending src/java/org/apache/commons/lang/time/FastDateFormat.java
        Sending src/test/org/apache/commons/lang/time/FastDateFormatTest.java
        Transmitting file data ..
        Committed revision 398530.

        Show
        Henri Yandell added a comment - Adding unit test for #39410. Implementing fix by switching from using Math.log to Integer.toString to figure out the number of digits. Sending src/java/org/apache/commons/lang/time/FastDateFormat.java Sending src/test/org/apache/commons/lang/time/FastDateFormatTest.java Transmitting file data .. Committed revision 398530.
        Hide
        Henri Yandell added a comment -

        Running through the source, the problem is that:

        log(1000) / log(10) is 2.9999999999999996 and not 3.0 as it should.

        Solving this by simplifying the method of finding out how many digits there are
        in a number - Integer.toString(value).length(). I've added an assert for value
        being negative (using Validate). Just in case.

        Show
        Henri Yandell added a comment - Running through the source, the problem is that: log(1000) / log(10) is 2.9999999999999996 and not 3.0 as it should. Solving this by simplifying the method of finding out how many digits there are in a number - Integer.toString(value).length(). I've added an assert for value being negative (using Validate). Just in case.
        Hide
        Henri Yandell added a comment -

        Created an attachment (id=18210)
        Unit test

        Show
        Henri Yandell added a comment - Created an attachment (id=18210) Unit test
        Hide
        Andrey Binetsky added a comment -
            • COM-2897 has been marked as a duplicate of this bug. ***
        Show
        Andrey Binetsky added a comment - COM-2897 has been marked as a duplicate of this bug. ***
        Hide
        Andrey Binetsky added a comment -

        for version 2.0 all is OK.

        Show
        Andrey Binetsky added a comment - for version 2.0 all is OK.

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrey Binetsky
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development