"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const moment = require("moment");
class MomentMapper {
    fromDb(value) {
        const parsed = moment(value.S, moment.ISO_8601);
        if (!parsed.isValid()) {
            throw new Error(`the value ${value} cannot be parsed into a valid moment date`);
        }
        return parsed;
    }
    toDb(value) {
        if (moment.isMoment(value)) {
            if (value.isValid()) {
                // always store in utc, default format is ISO_8601
                return {
                    S: value
                        .clone()
                        .utc()
                        .format(),
                };
            }
            else {
                throw new Error(`cannot map property value ${value}, because it is not a valid moment date`);
            }
        }
        else {
            throw new Error(`the value ${value} is not of type moment`);
        }
    }
}
exports.MomentMapper = MomentMapper;
//# sourceMappingURL=moment.mapper.js.map