class StatDisplayUtils {

    public static String convert(long totalTime) {
        Duration duration = Duration.ofMillis(totalTime);

        // Extract the days from the duration, then take it away so we can format the rest of the string.
        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();
    }

}