// retoor <retoor@molodetz.nl>

export class DateFormat {
    static format(value, includeTime = false) {
        if (!value) return "-";
        let input = value;
        if (typeof input === "string" && /^\d{4}-\d{2}-\d{2}$/.test(input)) {
            input = `${input}T00:00:00`;
        }
        const date = new Date(input);
        if (Number.isNaN(date.getTime())) return String(value).slice(0, 19);
        const dd = String(date.getDate()).padStart(2, "0");
        const mm = String(date.getMonth() + 1).padStart(2, "0");
        const yyyy = date.getFullYear();
        if (includeTime) {
            const hh = String(date.getHours()).padStart(2, "0");
            const mi = String(date.getMinutes()).padStart(2, "0");
            return `${dd}/${mm}/${yyyy} ${hh}:${mi}`;
        }
        return `${dd}/${mm}/${yyyy}`;
    }
}
