commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duncan Jones (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-815) DurationFormatUtils.formatPeriod() miss-calculation
Date Sat, 22 Sep 2012 10:05:07 GMT

    [ https://issues.apache.org/jira/browse/LANG-815?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13461101#comment-13461101
] 

Duncan Jones commented on LANG-815:
-----------------------------------

I don't believe this is a bug. Below is a test case that should demonstrate the issue, but
it passes just fine:

{code}
@Test
public void testLANG815() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(2012, 6, 30, 0, 0, 0);
    long startMillis = calendar.getTimeInMillis();
    
    calendar.set(2012, 8, 8);
    long endMillis = calendar.getTimeInMillis();
    
    
    assertEquals("1 9", DurationFormatUtils
            .formatPeriod(startMillis, endMillis, "M d"));
}
{code}
                
> DurationFormatUtils.formatPeriod() miss-calculation
> ---------------------------------------------------
>
>                 Key: LANG-815
>                 URL: https://issues.apache.org/jira/browse/LANG-815
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.1
>         Environment: JDK 1.7
>            Reporter: Naoya Sugioka
>         Attachments: duration-format.diff
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Hello,
> I just encountered an issue with DurationFormatUtils.formatPeriod()
> and here I suggest the patch.
> The problem is found when calcurating a duration between  June 30 to August 8.
> Duration must be 1 month and 9 days  (June 30 + 1 month = July 30,
> July 30 + 9 Days = August 8)
> but current logic tells this duration is 1 month and 8 days.
> then I found out the logic to adjust days value if it was negative by
> initial estimate. it uses start date
> (June in above case) but must use prev month of end date (July in
> above case). then days value was
> wrong since getActualMaximum() will return a wrong number.
> thank you,
> -Naoya

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message