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

[lang] DurationFormatUtils.formatDurationWords() incorrectly formats values ending in 1 but greater than 1

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.1
    • None
    • None
    • None
    • Operating System: Linux
      Platform: Other

    • 36522

    Description

      Currently, values ending in 1 but greater than 1 (41, for example) return a
      non-plural response (second, hour, day, etc). The culprit code appears to be at
      the end of the method:

      // handle plurals
      duration = StringUtils.replaceOnce(duration, "1 seconds", "1 second");
      duration = StringUtils.replaceOnce(duration, "1 minutes", "1 minute");
      duration = StringUtils.replaceOnce(duration, "1 hours", "1 hour");
      duration = StringUtils.replaceOnce(duration, "1 days", "1 day");

      One approach to fix this might be to use a regular expression to replace only if
      1 appears as a single digit rather than with another digit.

      I'm thinking of something like: (duration.replaceFirst("([^\\d])(
      d) seconds",
      "$1$2 second")

      Attachments

        Activity

          People

            Unassigned Unassigned
            asf.robmoore@xoxy.net Rob Moore
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: