@Test public void testDateAsMinsHoursDaysEtcAgo() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.add(Calendar.SECOND, -2); Date now = cal.getTime(); cal.add(Calendar.MINUTE, -1); Date oneMinsAgo = cal.getTime(); cal.add(Calendar.MINUTE, -1); Date twoMinsAgo = cal.getTime(); cal.add(Calendar.MINUTE, -57); Date fiveNineMinsAgo = cal.getTime(); cal.add(Calendar.HOUR, -1); Date hourAndfiveNineMinsAgo = cal.getTime(); cal.add(Calendar.HOUR, -1); Date twoHoursAndfiveNineMinsAgo = cal.getTime(); cal.add(Calendar.HOUR, -21); Date twoThreeHoursAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -1); Date dayAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -1); Date twoDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -4); Date sixDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -1); Date sevenDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -7); Date fourteenDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -15); Date twoNineDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -1); Date thirtyDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -30); Date sixtyDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -299); Date twoFiveNineDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -1); Date threeSixtyDaysAgo = cal.getTime(); cal.add(Calendar.DAY_OF_WEEK, -5); Date threeSixFiveDaysAgo = cal.getTime(); assertEquals("< 2 mins ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(now)); assertEquals("< 2 mins ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(oneMinsAgo)); assertEquals("2 mins ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(twoMinsAgo)); assertEquals("59 mins ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(fiveNineMinsAgo)); assertEquals("1 hour ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(hourAndfiveNineMinsAgo)); assertEquals("2 hours ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(twoHoursAndfiveNineMinsAgo)); assertEquals("23 hours ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(twoThreeHoursAgo)); assertEquals("47 hours ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(dayAgo)); assertEquals("2 days ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(twoDaysAgo)); assertEquals("6 days ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(sixDaysAgo)); assertEquals("a week ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(sevenDaysAgo)); assertEquals("2 weeks ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(fourteenDaysAgo)); assertEquals("4 weeks ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(twoNineDaysAgo)); assertEquals("a month ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(thirtyDaysAgo)); assertEquals("2 months ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(sixtyDaysAgo)); assertEquals("11 months ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(twoFiveNineDaysAgo)); assertEquals("12 months ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(threeSixtyDaysAgo)); assertEquals("> 1 year ago", TagLibFunctions.dateAsMinsHoursDaysEtcAgo(threeSixFiveDaysAgo)); }
public static String dateAsMinsHoursDaysEtcAgo(Date date) { float hours = DateTimeUtils.getMillisDiff(System.currentTimeMillis(), date.getTime(), Calendar.HOUR); if ( hours < 1f ) { int mins = (int) (hours * 60f); return (mins < 2) ? "< 2 mins ago" : mins + " mins ago"; } if ( hours < 2f ) { return "1 hour ago"; } if ( hours < 48f ) { return (int)hours + " hours ago"; } if ( hours < 24f * 7f) { return (int)(hours / 24f) + " days ago"; } if ( hours < 24f * 7f * 2f) { return "a week ago"; } if ( hours < 24f * 30f) { return (int)(hours / 24f / 7f) + " weeks ago"; } if ( hours < 24f * 30f * 2f) { return "a month ago"; } if ( hours < 24f * 365f) { return (int)(hours / 24f / 30f) + " months ago"; } return "> 1 year ago"; }
TagLibFunctions { public static String dateAsMinsHoursDaysEtcAgo(Date date) { float hours = DateTimeUtils.getMillisDiff(System.currentTimeMillis(), date.getTime(), Calendar.HOUR); if ( hours < 1f ) { int mins = (int) (hours * 60f); return (mins < 2) ? "< 2 mins ago" : mins + " mins ago"; } if ( hours < 2f ) { return "1 hour ago"; } if ( hours < 48f ) { return (int)hours + " hours ago"; } if ( hours < 24f * 7f) { return (int)(hours / 24f) + " days ago"; } if ( hours < 24f * 7f * 2f) { return "a week ago"; } if ( hours < 24f * 30f) { return (int)(hours / 24f / 7f) + " weeks ago"; } if ( hours < 24f * 30f * 2f) { return "a month ago"; } if ( hours < 24f * 365f) { return (int)(hours / 24f / 30f) + " months ago"; } return "> 1 year ago"; } }
TagLibFunctions { public static String dateAsMinsHoursDaysEtcAgo(Date date) { float hours = DateTimeUtils.getMillisDiff(System.currentTimeMillis(), date.getTime(), Calendar.HOUR); if ( hours < 1f ) { int mins = (int) (hours * 60f); return (mins < 2) ? "< 2 mins ago" : mins + " mins ago"; } if ( hours < 2f ) { return "1 hour ago"; } if ( hours < 48f ) { return (int)hours + " hours ago"; } if ( hours < 24f * 7f) { return (int)(hours / 24f) + " days ago"; } if ( hours < 24f * 7f * 2f) { return "a week ago"; } if ( hours < 24f * 30f) { return (int)(hours / 24f / 7f) + " weeks ago"; } if ( hours < 24f * 30f * 2f) { return "a month ago"; } if ( hours < 24f * 365f) { return (int)(hours / 24f / 30f) + " months ago"; } return "> 1 year ago"; }  }
TagLibFunctions { public static String dateAsMinsHoursDaysEtcAgo(Date date) { float hours = DateTimeUtils.getMillisDiff(System.currentTimeMillis(), date.getTime(), Calendar.HOUR); if ( hours < 1f ) { int mins = (int) (hours * 60f); return (mins < 2) ? "< 2 mins ago" : mins + " mins ago"; } if ( hours < 2f ) { return "1 hour ago"; } if ( hours < 48f ) { return (int)hours + " hours ago"; } if ( hours < 24f * 7f) { return (int)(hours / 24f) + " days ago"; } if ( hours < 24f * 7f * 2f) { return "a week ago"; } if ( hours < 24f * 30f) { return (int)(hours / 24f / 7f) + " weeks ago"; } if ( hours < 24f * 30f * 2f) { return "a month ago"; } if ( hours < 24f * 365f) { return (int)(hours / 24f / 30f) + " months ago"; } return "> 1 year ago"; }  static String toCssRGBColor(float value); static String toCssRGBColor(float value, float saturation); static String toCssRGBColor(Score score); static String toCssRGBColor(Score score, float sat); static int toPercent(Score score); static List<T> toList(Iterator<T> items); static Float forwardsScore(Result<T> result, String matcher); static Float reverseScore(Result<T> result, String matcher); static Float forwardsTotal(Result<T> result); static Float reverseTotal(Result<T> result); static String toString(Object object); static String dateAsMinsHoursDaysEtcAgo(Date date); }
TagLibFunctions { public static String dateAsMinsHoursDaysEtcAgo(Date date) { float hours = DateTimeUtils.getMillisDiff(System.currentTimeMillis(), date.getTime(), Calendar.HOUR); if ( hours < 1f ) { int mins = (int) (hours * 60f); return (mins < 2) ? "< 2 mins ago" : mins + " mins ago"; } if ( hours < 2f ) { return "1 hour ago"; } if ( hours < 48f ) { return (int)hours + " hours ago"; } if ( hours < 24f * 7f) { return (int)(hours / 24f) + " days ago"; } if ( hours < 24f * 7f * 2f) { return "a week ago"; } if ( hours < 24f * 30f) { return (int)(hours / 24f / 7f) + " weeks ago"; } if ( hours < 24f * 30f * 2f) { return "a month ago"; } if ( hours < 24f * 365f) { return (int)(hours / 24f / 30f) + " months ago"; } return "> 1 year ago"; }  static String toCssRGBColor(float value); static String toCssRGBColor(float value, float saturation); static String toCssRGBColor(Score score); static String toCssRGBColor(Score score, float sat); static int toPercent(Score score); static List<T> toList(Iterator<T> items); static Float forwardsScore(Result<T> result, String matcher); static Float reverseScore(Result<T> result, String matcher); static Float forwardsTotal(Result<T> result); static Float reverseTotal(Result<T> result); static String toString(Object object); static String dateAsMinsHoursDaysEtcAgo(Date date);  }