UNPKG

mvom

Version:

Multivalue Object Mapper

52 lines (47 loc) 1.89 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _dataTransformers = require("../dataTransformers"); var _BaseScalarType = _interopRequireDefault(require("./BaseScalarType")); var _ISOCalendarDateType = _interopRequireDefault(require("./ISOCalendarDateType")); var _ISOTimeType = _interopRequireDefault(require("./ISOTimeType")); /** An ISOCalendarDateTime Schema Type */ class ISOCalendarDateTimeType extends _BaseScalarType.default { /** Data transformer */ /** ISOCalendarDateType instance to use for transformations and validations of the date part of the DateTime */ /** ISOTimeType instance to use for transformations and validations of the time part of the DateTime */ constructor(definition, options = {}) { super(definition, options); const { dbFormat = 'ms' } = definition; this.isoCalendarDateType = new _ISOCalendarDateType.default({ ...definition, type: 'ISOCalendarDate' }, options); this.isoTimeType = new _ISOTimeType.default({ ...definition, type: 'ISOTime', dbFormat }, options); this.dataTransformer = new _dataTransformers.ISOCalendarDateTimeDataTransformer(dbFormat); } /** ISOCalendarDateTime data type validator */ validateType = value => { if (value == null) { return true; } if (typeof value !== 'string') { // must be a string value return false; } const [datePart, timePart] = value.split('T'); const dateValidationResult = this.isoCalendarDateType.validate(datePart); const timeValidationResult = this.isoTimeType.validate(timePart); return dateValidationResult.length === 0 && timeValidationResult.length === 0; }; } var _default = exports.default = ISOCalendarDateTimeType;