Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-982

DurationFormatUtils.formatDuration(61999, "s.SSSS") - ms field size should be 4 digits

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.3.1
    • lang.time.*
    • None

    Description

      DurationFormatUtils.formatDuration(61999, "s.SSSS") generates the wrong number of places for the millisecond field. It should produce 61.0999 but it generates 61.999.

      This is an unlikely format, but there is no indication that the millisecond field is a maximum of 3 digits when it happens to follow a seconds field.

      This issue occurs because of the way the code attempts to ensure that 3 places are shown in a format if milliseconds follows seconds.
      The code currently adds 1000 and then drops the first digit.
      The simplest way to allow an arbitrary number of digits is to use at least 3 for the count field.
      Alternatively, if exactly 3 digits are required it would be simpler to just use a count of 3.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sebb Sebb
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: