You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2006/06/19 14:50:31 UTC

[jira] Resolved: (LANG-140) [lang] DurationFormatUtils.formatPeriod() returns the wrong result

     [ http://issues.apache.org/jira/browse/LANG-140?page=all ]
     
Henri Yandell resolved LANG-140:
--------------------------------

    Resolution: Fixed
     Assign To: Henri Yandell


Fix committed. Played with it while on holiday and found that there was a nice simple fix (least all the unit tests pass with this fix and it seems to make sense). The nightly build appears to be down currently, so the way to get to the code would be to svn co https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk and build a jar using ant or maven.

svn ci -m "Added unit test for LANG-140 - thanks to Yu Peng for the test case" src/t
est/org/apache/commons/lang/time/DurationFormatUtilsTest.java 
Sending        src/test/org/apache/commons/lang/time/DurationFormatUtilsTest.java
Transmitting file data .
Committed revision 415316.

 svn ci -m "Committing fix for LANG-140. By reversing the order of field calculation,
 Yu Peng's bug goes away" src/java/org/apache/commons/lang/time/DurationFormatUtils.java 
Sending        src/java/org/apache/commons/lang/time/DurationFormatUtils.java
Transmitting file data .
Committed revision 415317.

> [lang] DurationFormatUtils.formatPeriod() returns the wrong result
> ------------------------------------------------------------------
>
>          Key: LANG-140
>          URL: http://issues.apache.org/jira/browse/LANG-140
>      Project: Commons Lang
>         Type: Bug

>  Environment: Operating System: Windows XP
> Platform: PC
>     Reporter: yu.peng
>     Assignee: Henri Yandell
>      Fix For: 2.2
>  Attachments: 38401.patch, LANG-140.patch, Period.java
>
> /**
>  * lib: commons-lang-2.1.jar
>  * 
>  * this class run result.
>  * Result:
>  *    Date1->Date2=2006/01/26 18:47:34 000->2006/02/26 10:47:34 000===0000”N01
> ŒŽ-1“ú 16:00:00 000
>  *    Date1->Date2=2006/01/26 18:47:34 000->2006/02/26 10:47:34 000===0000/01/-
> 1 16:00:00 000
>  * want result:
>  *    Date1->Date2=2006/01/26 18:47:34 000->2006/02/26 10:47:34 000===0000”N00ŒŽ
> 30“ú 16:00:00
>  *    Date1->Date2=2006/01/26 18:47:34 000->2006/02/26 10:47:34 
> 000===0000/00/30 16:00:00
>  * 
>  * 
>  * the results are wrong.
>  * 
>  */
> import java.text.SimpleDateFormat;
> import java.util.Calendar;
> import java.util.Date;
> import org.apache.commons.lang.time.DurationFormatUtils;
> public class Test {
>     
>     static SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd 
> HH:mm:ss SSS");
>     public static void main(String[] args) {
>         Date date1 = newDate(2006, 1, 26, 18, 47, 34);
>         Date date2 = newDate(2006, 2, 26, 10, 47, 34);
>         System.out.println("Date1->Date2=" + 
>                 formatter.format(date1) + "->" + formatter.format(date2) 
> + "===" +  
>                 DurationFormatUtils.formatPeriod(date1.getTime(), date2.getTime
> (), "yyyy”NMMŒŽdd“ú HH:mm:ss SSS") );
>         System.out.println("Date1->Date2=" + 
>                 formatter.format(date1) + "->" + formatter.format(date2) 
> + "===" +  
>                 DurationFormatUtils.formatPeriod(date1.getTime(), date2.getTime
> (), "yyyy/MM/dd HH:mm:ss SSS") );
>     
>     }
>     public static Date newDate(int y, int m, int d, int h, int mi, int s) {
>         Calendar calendar1 = Calendar.getInstance();
>         calendar1.clear();
>         calendar1.set(y, m - 1, d, h, mi, s);
>         Date date1 = calendar1.getTime();
>         return date1;
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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