StatDisplayUtils { public static String convert(long totalTime) { Duration duration = Duration.ofMillis(totalTime); long days = duration.toDaysPart(); Duration durationLessDays = duration.minusDays(days); String result = ""; if (days > 0) { result += String.format("%dd ", days); } return result + durationLessDays.toString() .substring(2) .replaceAll("(\\d[HMS])(?!$)", "$1 ") .toLowerCase(); }  static HomeButton createHomeButtonInStatsScreen(GazePlay gazePlay, StatsContext statsContext); static LineChart<String, Number> buildLineChart(Stats stats, final Region root); static AreaChart<Number, Number> buildAreaChart(LinkedList<FixationPoint> points, final Region root); static ImageView buildGazeMetrics(Stats stats, final Region root); static String convert(long totalTime);  }
@Test void shouldConvertTimeToString() { final Calendar cal = Calendar.getInstance(); cal.set(2020, Calendar.JANUARY, 28, 13, 25, 20); long start = cal.getTimeInMillis(); cal.set(2020, Calendar.JANUARY, 28, 14, 25, 25); long end = cal.getTimeInMillis(); String result = StatDisplayUtils.convert(end - start); assertTrue(result.contains("1h 5s")); cal.set(2020, Calendar.JANUARY, 28, 13, 25, 20); start = cal.getTimeInMillis(); cal.set(2020, Calendar.JANUARY, 29, 14, 26, 25); end = cal.getTimeInMillis(); result = StatDisplayUtils.convert(end - start); assertTrue(result.contains("1d 1h 1m 5s")); }