PrettyTime { public String formatDuration(Date then) { Duration duration = approximateDuration(then); return formatDuration(duration); } PrettyTime();  PrettyTime(String overrideResourceBundle);  PrettyTime(final Date reference);  PrettyTime(final Date reference, String overrideResourceBundle);  PrettyTime(final Locale locale);  PrettyTime(final Locale locale, String overrideResourceBundle);  PrettyTime(final Date reference, final Locale locale);  PrettyTime(final Date reference, final Locale locale, String overrideResourceBundle); Duration approximateDuration(Date then); List<Duration> calculatePreciseDuration(Date then); String format(Date then); String format(Calendar then); String format(final Duration duration); String format(final List<Duration> durations); String formatUnrounded(Date then); String formatUnrounded(Calendar then); String formatUnrounded(Duration duration); String formatUnrounded(List<Duration> durations); String formatDuration(Date then); String formatDuration(Calendar then); String formatDuration(Duration duration); String formatDuration(final List<Duration> durations); String formatDurationUnrounded(Date then); String formatDurationUnrounded(Calendar then); String formatDurationUnrounded(Duration duration); String formatDurationUnrounded(final List<Duration> durations); TimeFormat getFormat(TimeUnit unit); Date getReference(); PrettyTime setReference(final Date timestamp); List<TimeUnit> getUnits(); @SuppressWarnings("unchecked") UNIT getUnit(final Class<UNIT> unitType); PrettyTime registerUnit(final TimeUnit unit, TimeFormat format); TimeFormat removeUnit(final Class<UNIT> unitType); TimeFormat removeUnit(final TimeUnit unit); Locale getLocale(); PrettyTime setLocale(Locale locale); @Override String toString(); List<TimeUnit> clearUnits();  }
@Test public void testFormatDuration() throws Exception { long tenMinMillis = java.util.concurrent.TimeUnit.MINUTES.toMillis(10); Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); String result = t.formatDuration(tenMinAgo); Assert.assertTrue(result.equals("10 minutes")); }
@Test public void testFormatDurationWithRounding() throws Exception { long tenMinMillis = java.util.concurrent.TimeUnit.MINUTES.toMillis(10) + 1000 * 40; Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); String result = t.formatDuration(tenMinAgo); Assert.assertTrue(result.equals("11 minutes")); }