コード例 #1
0
  @Test
  public void testRounding() throws Exception {
    PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3 + 1000 * 60 * 45));
    Duration duration = t.approximateDuration(new Date(0));
    TimeFormat format = duration.getUnit().getFormat();

    assertEquals("4 hours", format.format(duration));
    assertEquals("3 hours", format.formatUnrounded(duration));
  }
コード例 #2
0
  @Test
  public void testDecorating() throws Exception {
    PrettyTime t = new PrettyTime();
    TimeFormat format = new BasicTimeFormat().setFutureSuffix("from now").setPastSuffix("ago");

    Duration duration = t.approximateDuration(new Date(System.currentTimeMillis() + 1000));
    assertEquals("some time from now", format.decorate(duration, "some time"));

    duration = t.approximateDuration(new Date(System.currentTimeMillis() - 10000));
    assertEquals("some time ago", format.decorate(duration, "some time"));
  }