"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertDate = void 0;
const date_fns_1 = require("date-fns");
const lodash_1 = require("lodash");
/**
 * Healthie seemingly uses a custom format for dates.
 * Their documentation platform does not explicitly say which format is used, but based
 * on testing we've identified 'yyyy-MM-dd HH:mm:ss XX' (example: `2023-06-05 14:10:00 +0200`)
 * as the format used. This has been tested in:
 * - appointment date
 *
 * This function can be used to convert from the format used by Healthie to the format expected
 * by orchestration (ISO8601).
 */
const convertDate = (dateString, formatString = 'yyyy-MM-dd HH:mm:ss XX') => {
    if ((0, lodash_1.isNil)(dateString)) {
        return undefined;
    }
    const parsedDate = (0, date_fns_1.parse)(dateString, formatString, new Date());
    if ((0, date_fns_1.isValid)(parsedDate)) {
        return (0, date_fns_1.formatISO)(parsedDate);
    }
    return undefined;
};
exports.convertDate = convertDate;
//# sourceMappingURL=dateValidation.js.map