"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateUtil = void 0;
const ms_1 = __importDefault(require("ms"));
class DateUtil {
    static parseDuration(duration) {
        if (typeof duration === 'number') {
            return duration;
        }
        return (0, ms_1.default)(duration);
    }
    static addDuration(date, duration) {
        const milliseconds = this.parseDuration(duration);
        return new Date(date.getTime() + milliseconds);
    }
    static isPast(date) {
        return date < new Date();
    }
    static isFuture(date) {
        return date > new Date();
    }
    static getTimeUntil(date) {
        const remaining = Math.max(0, date.getTime() - Date.now());
        const seconds = Math.floor(remaining / 1000);
        const minutes = Math.floor(seconds / 60);
        const hours = Math.floor(minutes / 60);
        const days = Math.floor(hours / 24);
        return {
            milliseconds: remaining,
            seconds,
            minutes,
            hours,
            days,
            formatted: (0, ms_1.default)(remaining, { long: true }),
        };
    }
    static format(date, format = 'short') {
        switch (format) {
            case 'long':
                return date.toLocaleString();
            case 'iso':
                return date.toISOString();
            case 'short':
            default:
                return date.toLocaleDateString();
        }
    }
    static getRelativeTime(date) {
        const diff = Date.now() - date.getTime();
        if (diff < 0) {
            return 'in the future';
        }
        const seconds = Math.floor(diff / 1000);
        const minutes = Math.floor(seconds / 60);
        const hours = Math.floor(minutes / 60);
        const days = Math.floor(hours / 24);
        const months = Math.floor(days / 30);
        const years = Math.floor(days / 365);
        if (years > 0)
            return `${years} year${years > 1 ? 's' : ''} ago`;
        if (months > 0)
            return `${months} month${months > 1 ? 's' : ''} ago`;
        if (days > 0)
            return `${days} day${days > 1 ? 's' : ''} ago`;
        if (hours > 0)
            return `${hours} hour${hours > 1 ? 's' : ''} ago`;
        if (minutes > 0)
            return `${minutes} minute${minutes > 1 ? 's' : ''} ago`;
        if (seconds > 10)
            return `${seconds} seconds ago`;
        return 'just now';
    }
}
exports.DateUtil = DateUtil;
//# sourceMappingURL=date.util.js.map