Commons Lang
  1. Commons Lang
  2. LANG-140

[lang] DurationFormatUtils.formatPeriod() returns the wrong result

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: PC

      Description

      /**

      • 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; }

      }

      1. ASF.LICENSE.NOT.GRANTED--38401.patch
        1 kB
        Henri Yandell
      2. ASF.LICENSE.NOT.GRANTED--Period.java
        4 kB
        yu.peng
      3. LANG-140.patch
        4 kB
        Henri Yandell

        Activity

          People

          • Assignee:
            Henri Yandell
            Reporter:
            yu.peng
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development