package fr.Skydust.JdrBot.utils;

import java.time.Duration;

public class DurationUtils {

    public static String formatDuration(Duration duration) {
        long seconds = duration.getSeconds();
        long absSeconds = Math.abs(seconds);
        String positive = String.format(
                "%d:%02d:%02d",
                absSeconds / 3600,
                (absSeconds % 3600) / 60,
                absSeconds % 60);
        return seconds < 0 ? "-" + positive : positive;
    }

    public static String formatDurationSmooth(Duration duration) {
        long absSeconds = Math.abs(duration.getSeconds());

        if((absSeconds/3600) == 0) {//Hours
            if(((absSeconds%3600)/60) == 0)
            {//Minutes
                return String.format("%d secondes", absSeconds % 60);
            }
            return String.format("%d minutes",  (absSeconds % 3600) / 60);
        }
        return String.format("%d heures",  (absSeconds /3600));
    }
}
