You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/09/06 17:45:18 UTC

DO NOT REPLY [Bug 36522] New: - DurationFormatUtils.formatDurationWords() incorrectly formats values ending in 1 but greater than 1

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=36522>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=36522

           Summary: DurationFormatUtils.formatDurationWords() incorrectly
                    formats values ending in 1 but greater than 1
           Product: Commons
           Version: 2.1 Final
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: asf.robmoore@xoxy.net


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")

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org