"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.relativeDateToDateRange = relativeDateToDateRange;
/**
 * @private
 * Convert a RelativeDate to a DateRange<number>
 * @param relative
 * @returns
 */
function relativeDateToDateRange(relative) {
    // hash of offsets
    const offsetMs = {
        min: 1000 * 60,
        hours: 1000 * 60 * 60,
        days: 1000 * 60 * 60 * 24,
        weeks: 1000 * 60 * 60 * 24 * 7,
    };
    const now = new Date();
    // default
    const result = {
        type: "date-range",
        from: now.getTime(),
        to: now.getTime(),
    };
    //
    switch (relative.unit) {
        case "hours":
        case "days":
        case "weeks":
            result.from = result.to - offsetMs[relative.unit] * relative.num;
            break;
        case "months":
            // get the current month and subtract num
            // NOTE: when the previous month has fewer days than this month
            // setMonth() will return a date w/in the current month
            // example: 3/30 -> 3/2 b/c there is no 2/28
            now.setMonth(now.getMonth() - relative.num);
            result.from = now.getTime();
            break;
        case "years":
            now.setFullYear(now.getFullYear() - relative.num);
            result.from = now.getTime();
            break;
    }
    return result;
}
//# sourceMappingURL=relativeDateToDateRange.js.map