DateUtils { public static String toSimpleElapsedTime(Date date) { long diff = (System.currentTimeMillis() - date.getTime()) / 1000; if (diff < 60) { return "less than a minute ago"; } diff /= 60; if (diff < 60) { return pluralize(diff, "minute") + " ago"; } diff /= 60; if (diff < 24) { return pluralize(diff, "hour") + " ago"; } else { diff /= 24; return pluralize(diff, "day") + " ago"; } }  static Date fromString(String string, String format); static Date fromString(String string); static String toString(Date date, String format); static String toString(Date date); static String toLabel(Date date, boolean isShortened); static String toLabel(Date date); static boolean isSameDay(Date a, Date b); static Date addTime(Date date, int field, int amount); static String toSimpleElapsedTime(Date date);  }
@Test public void toSimpleElapsedTime_underminute() { assertEquals("less than a minute ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - (30 * SECOND)))); }
@Test public void toSimpleElapsedTime_oneminute() { assertEquals("1 minute ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - (65 * SECOND)))); }
@Test public void toSimpleElapsedTime_underhour() { assertEquals("5 minutes ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - ((5 * MINUTE) + (10 * SECOND))))); }
@Test public void toSimpleElapsedTime_onehour() { assertEquals("1 hour ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - (65 * MINUTE)))); }
@Test public void toSimpleElapsedTime_underday() { assertEquals("5 hours ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - ((5 * HOUR) + (10 * MINUTE))))); }
@Test public void toSimpleElapsedTime_oneday() throws ParseException { assertEquals("1 day ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - ((1 * DAY) + (10 * MINUTE))))); }
@Test public void toSimpleElapsedTime_multiday() throws ParseException { assertEquals("5 days ago", DateUtils.toSimpleElapsedTime(new Date(new Date().getTime() - ((5 * DAY) + (10 * MINUTE))))); }
@Test (expected=NullPointerException.class) public void toSimpleElapsedTime_null() { assertEquals(null, DateUtils.toSimpleElapsedTime(null)); }