DateUtil { public static String formatDelta(long deltaInMillis) { StringBuilder sb = new StringBuilder(); if (deltaInMillis < 0) { sb.append("-"); } final long abs = Math.abs(deltaInMillis); final long millis = abs % SECOND; final long seconds = (abs % MINUTE) / SECOND; final long minutes = (abs % HOUR) / MINUTE; final long hours = (long) Math.floor(((double) abs) / HOUR); if (hours > 3) { sb.append(hours).append("h"); } else if (hours > 0) { sb.append(hours).append("h"); if (minutes > 0) { sb.append(" ").append(minutes).append("m"); } } else if (minutes > 4) { sb.append(minutes).append("m"); } else if (minutes > 0) { sb.append(minutes).append("m"); if (seconds > 0) { sb.append(" ").append(seconds).append("s"); } } else if (seconds > 3) { sb.append(seconds).append("s"); } else if (seconds > 0) { sb.append(seconds); if (millis != 0) { final String s = Long.toString(Math.round((double) millis / 100)); sb.append(",").append(s); } sb.append("s"); } else { sb.append(millis).append("ms"); } return sb.toString(); }  Collection<String> allDateFormats(); Set<String> dateFormatsInAllLocales(); Collection<String> getPredefinedDateFormats(); Set<String> matchingDateFormat(Collection<String> definedDateFormats, Collection<String> dates); static String formatDelta(long deltaInMillis);  }
@Test(dataProvider = "data") public void testFormatDelta(int deltaInMs, String expected) { final String delta = DateUtil.formatDelta(deltaInMs); assertEquals(delta, expected); }