DateTimeUtils { public static String millisecondsToDecimalHumanTime(long period) { double periodD = period; NumberFormat numFormat = new DecimalFormat("#.##"); if (period < MILLIS_IN_SECOND) { return String.format("%s milliseconds", numFormat.format(periodD)); } else if (period < MILLIS_IN_MINUTE) { return String.format("%s seconds", numFormat.format(periodD / MILLIS_IN_SECOND)); } else if (period < MILLIS_IN_HOUR) { return String.format("%s minutes", numFormat.format(periodD / MILLIS_IN_MINUTE)); } else if (period < MILLIS_IN_DAY) { return String.format("%s hours", numFormat.format(periodD / MILLIS_IN_HOUR)); } else { return String.format("%s days", numFormat.format(periodD / MILLIS_IN_DAY)); } } private  DateTimeUtils(); static String timestampToHumanDateAndTimeLocal(long timestamp); static String timestampToHumanDateAndTimeAde(long timestamp); static String timestampToHumanDateAndTimeUTC(long timestamp); static String millisecondsToHumanTime(long period); static String millisecondsToDecimalHumanTime(long period); static long getDayStartTimeLocal(long startTime); static String timestampToHumanDateAndTimeAndStampLocal(long time); static String timestampToHumanDateAndTimeAndStampUTC(long time); static long getTimeStampLocal(int year, int month, int day, double frac); static Date getCurrentDate(); static TimeZone parseTimeZone(String id); static SimpleDateFormat getNewGmtSimpleDateFormat(String format); static SimpleDateFormat getNewGmtSimpleDateFormat(String format, boolean lenient); static Calendar getGmtGregorianCalendar(); static Calendar getGmtGregorianCalendar(int year, int month, int dayOfMonth); static long parseDuration(String strDuration); static final long SECONDS_IN_MINUTE; static final long MINUTES_IN_HOUR; static final long HOURS_IN_DAY; static final long DAYS_IN_WEEK; static final long MILLIS_IN_SECOND; static final long HALF_MILLIS_IN_SECOND; static final long MILLIS_IN_MINUTE; static final long MILLIS_IN_HOUR; static final long MILLIS_IN_DAY; static final long MILLIS_IN_WEEK; static final TimeZone GMT_TIMEZONE; static final LazyObj<TimeZone> ADE_TIMEZONE; }
@Test public void testMillisecondsToDecimalHumanTimePeriodLessThanMillisecondsInSec(){ Long period = 999L; assertEquals("Period of time < 1 second","999 milliseconds",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }
@Test public void testMillisecondsToDecimalHumanTimePeriodLessThanMillisecondsInMin(){ Long period = 1001L; assertEquals("Period of time < 1 minute","1 seconds",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }
@Test public void testMillisecondsToDecimalHumanTimePeriodMoreThanMillisecondsInMin(){ Long period = 60001L; assertEquals("Period of time >= 1 minute","1 minutes",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }
@Test public void testMillisecondsToDecimalHumanTimePeriodLessThanMillisecondsInHour(){ Long period = 360000L; assertEquals("Period of time < 1 hour","6 minutes",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }
@Test public void testMillisecondsToDecimalHumanTimePeriodMoreThanMillisecondsInHour(){ Long period = 3600001L; assertEquals("Period of time >= 1 hour","1 hours",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }
@Test public void testMillisecondsToDecimalHumanTimePeriodLessThanMillisecondsInDay(){ Long period = 82800000L; assertEquals("Period of time < 1 day","23 hours",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }
@Test public void testMillisecondsToDecimalHumanTimePeriodMoreThanMillisecondsInDay(){ Long period = 86400000L; assertEquals("Period of time >= to 1 day","1 days",DateTimeUtils.millisecondsToDecimalHumanTime(period)); }