import * as moment from 'moment';
var MomentMapper = /** @class */ (function () {
    function MomentMapper() {
    }
    MomentMapper.prototype.fromDb = function (value) {
        var 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;
    };
    MomentMapper.prototype.toDb = function (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");
        }
    };
    return MomentMapper;
}());
export { MomentMapper };
//# sourceMappingURL=moment.mapper.js.map