public static String format(Duration duration, boolean concise, int elements) {
        long seconds = duration.getSeconds();
        StringBuilder output = new StringBuilder();
        int outputSize = 0;

        for (Unit unit : UNITS) {
            long n = seconds / unit.duration;
            if (n > 0) {
                seconds -= unit.duration * n;
                output.append(' ').append(n).append(unit.toString(concise, n));
                outputSize++;
            }
            if (seconds <= 0 || outputSize >= elements) {
                break;
            }
        }

        if (output.length() == 0) {
            return "0" + (UNITS[UNITS.length - 1].toString(concise, 0));
        }
        return output.substring(1);
    }
Formats {@code duration} as a string, either in a {@code concise} (1 letter)
or full length format, displaying up to the specified number of {@code elements}.

@param duration the duration
@param concise  if the output should be concisely formatted
@param elements the maximum number of elements to display
@return the formatted string
helper/src/main/java/me/lucko/helper/time/DurationFormatter.java