"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatDate = formatDate;
const actions_core_1 = require("@segment/actions-core");
function formatDate(input) {
    const ymdRegex = /^\d{4}-\d{2}-\d{2}$/;
    if (ymdRegex.test(input)) {
        return input;
    }
    const date = new Date(input);
    if (isNaN(date.getTime())) {
        throw new actions_core_1.PayloadValidationError(`Invalid date string: ${input}`);
    }
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    return `${year}-${month}-${day}`;
}
//# sourceMappingURL=functions.js.map