DateUtils { public static String friendlyFormat(Context context, Date date) { long difference = System.currentTimeMillis() - date.getTime(); if (difference < 0) { return null; } else if (difference < MINUTE) { return context.getResources().getQuantityString(R.plurals.post_seconds, (int) (difference / SECOND)); } else if (difference < HOUR) { return context.getResources().getQuantityString(R.plurals.post_minutes, (int) (difference / MINUTE), (int) (difference / MINUTE)); } else if (difference < DAY) { return context.getResources().getQuantityString(R.plurals.post_hours, (int) (difference / HOUR), (int) (difference / HOUR)); } else if (difference < MONTH) { return context.getResources().getQuantityString(R.plurals.post_days, (int) (difference / DAY), (int) (difference / DAY)); } else if (difference < YEAR) { return context.getResources().getQuantityString(R.plurals.post_months, (int) (difference / MONTH), (int) (difference / MONTH)); } else { return context.getResources().getQuantityString(R.plurals.post_years, (int) (difference / YEAR), (int) (difference / YEAR)); } }  static String friendlyFormat(Context context, Date date);  }
@Test public void shouldReturnNullForFutureDate() { Date futureDate = new Date(System.currentTimeMillis() + 1000000); String formatted = DateUtils.friendlyFormat(RuntimeEnvironment.application, futureDate); assertThat(formatted, nullValue()); }