"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatDate = exports.dateFormats = void 0;
/** Predefined selection of date formats using DateTimeFormatOptions. */
exports.dateFormats = {
    'DD MM YYYY': { year: 'numeric', month: '2-digit', day: '2-digit' },
    'DD MM YYYY, HH:MM': { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' },
    'DD MMM': { month: 'short', day: '2-digit' },
    'DD MMM YYYY': { year: 'numeric', month: 'short', day: '2-digit' },
    'DD MMM YYYY, HH:MM': { year: 'numeric', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' },
    'DD MMM, HH:MM': { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' },
    'HH:MM': { locales: 'en-GB', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' },
    'MMM D, YYYY': { locales: 'en-US', year: 'numeric', month: 'short', day: 'numeric' },
    'YYYY/MM/DD': { locales: 'en-ZA' },
    'YYYY-MM-DD': { locales: 'fr-CA' },
    'YYYY/MM/DD, HH:MM': { locales: 'en-ZA', hour: '2-digit', minute: '2-digit' },
    'YYYY-MM-DD, HH:MM': { locales: 'fr-CA', timeStyle: 'short' },
    'YYYY-MM-DD, HH:MM:SS': { locales: 'fr-CA' },
};
/**
 * Structures given date string, milliseconds number or Date object according to the chosen format.
 * Uses toLocalDateString internally. Predefined formats specify initial options, which can be overwritten.
 * @param date - string, number or Date object accepted by Date() constructor
 * @param format - predefined configuration of DateTimeFormatOptions
 * @param options - configuration of toLocaleDateString method
 */
function formatDate(date, format = 'DD MM YYYY', options) {
    const formatOptions = exports.dateFormats[format];
    const _a = Object.assign(Object.assign({}, formatOptions), options), { locales } = _a, mergedOptions = __rest(_a, ["locales"]);
    if (format === 'YYYY-MM-DD, HH:MM:SS' || format === 'YYYY-MM-DD, HH:MM') {
        return date
            ? new Date(date).toLocaleDateString(locales) + ', ' + new Date(date).toLocaleTimeString(undefined, mergedOptions)
            : '';
    }
    if (format === 'HH:MM') {
        return date ? new Date(date).toLocaleTimeString(locales, mergedOptions) : '';
    }
    return date ? new Date(date).toLocaleDateString(locales, mergedOptions) : '';
}
exports.formatDate = formatDate;
//# sourceMappingURL=formatDate.js.map