DateUtils { public static String toLabel(Date date, boolean isShortened) { if (date == null) { return null; } if (isShortened) { long diff = (new Date().getTime() - date.getTime()) / 1000; if (diff < 60) { return "less than a minute ago"; } else if ((diff /= 60) < 60) { return diff == 1 ? "1 minute ago" : diff + " minutes ago"; } else if ((diff /= 60) < 24) { return diff == 1 ? "1 hour ago" : diff + " hours ago"; } } return toString(date, "EEE, MMM d, yyyy, h:mm a zz"); }  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 toLabel_underminute() { assertEquals("less than a minute ago", DateUtils.toLabel(new Date(new Date().getTime() - (30 * SECOND)), true)); }
@Test public void toLabel_oneminute() { assertEquals("1 minute ago", DateUtils.toLabel(new Date(new Date().getTime() - (65 * SECOND)), true)); }
@Test public void toLabel_underhour() { assertEquals("5 minutes ago", DateUtils.toLabel(new Date(new Date().getTime() - ((5 * MINUTE) + (10 * SECOND))), true)); }
@Test public void toLabel_onehour() { assertEquals("1 hour ago", DateUtils.toLabel(new Date(new Date().getTime() - (65 * MINUTE)), true)); }
@Test public void toLabel_underday() { assertEquals("5 hours ago", DateUtils.toLabel(new Date(new Date().getTime() - ((5 * HOUR) + (10 * MINUTE))), true)); }
@Test public void toLabel_null() { assertEquals(null, DateUtils.toLabel(null, true)); }
@Test public void toLabel() { assertEquals("less than a minute ago", DateUtils.toLabel(new Date(new Date().getTime() - (30 * SECOND)))); }