Exemplo n.º 1
0
 @Test
 public void testLANG984() { // Long durations
   assertEquals("0", DurationFormatUtils.formatDuration(0, "S"));
   assertEquals(
       Integer.toString(Integer.MAX_VALUE),
       DurationFormatUtils.formatDuration(Integer.MAX_VALUE, "S"));
   long maxIntPlus = Integer.MAX_VALUE;
   maxIntPlus++;
   assertEquals(Long.toString(maxIntPlus), DurationFormatUtils.formatDuration(maxIntPlus, "S"));
   assertEquals(
       Long.toString(Long.MAX_VALUE), DurationFormatUtils.formatDuration(Long.MAX_VALUE, "S"));
 }
Exemplo n.º 2
0
 @Test
 public void testLANG982() { // More than 3 millisecond digits following a second
   assertEquals("61.999", DurationFormatUtils.formatDuration(61999, "s.S"));
   assertEquals("1 1999", DurationFormatUtils.formatDuration(61999, "m S"));
   assertEquals("61.999", DurationFormatUtils.formatDuration(61999, "s.SSS"));
   assertEquals("1 1999", DurationFormatUtils.formatDuration(61999, "m SSS"));
   assertEquals("61.0999", DurationFormatUtils.formatDuration(61999, "s.SSSS"));
   assertEquals("1 1999", DurationFormatUtils.formatDuration(61999, "m SSSS"));
   assertEquals("61.00999", DurationFormatUtils.formatDuration(61999, "s.SSSSS"));
   assertEquals("1 01999", DurationFormatUtils.formatDuration(61999, "m SSSSS"));
 }
Exemplo n.º 3
0
  @Test
  public void testFormatDuration() {
    long duration = 0;
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "M"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "d"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "H"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "m"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "s"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "S"));
    assertEquals("0000", DurationFormatUtils.formatDuration(duration, "SSSS"));
    assertEquals("0000", DurationFormatUtils.formatDuration(duration, "yyyy"));
    assertEquals("0000", DurationFormatUtils.formatDuration(duration, "yyMM"));

    duration = 60 * 1000;
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "M"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "d"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "H"));
    assertEquals("1", DurationFormatUtils.formatDuration(duration, "m"));
    assertEquals("60", DurationFormatUtils.formatDuration(duration, "s"));
    assertEquals("60000", DurationFormatUtils.formatDuration(duration, "S"));
    assertEquals("01:00", DurationFormatUtils.formatDuration(duration, "mm:ss"));

    final Calendar base = Calendar.getInstance();
    base.set(2000, 0, 1, 0, 0, 0);
    base.set(Calendar.MILLISECOND, 0);

    final Calendar cal = Calendar.getInstance();
    cal.set(2003, 1, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    duration =
        cal.getTime().getTime() - base.getTime().getTime(); // duration from 2000-01-01 to cal
    // don't use 1970 in test as time zones were less reliable in 1970 than now
    // remember that duration formatting ignores time zones, working on strict hour lengths
    final int days = 366 + 365 + 365 + 31;
    assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
  }