UNPKG

@opra/common

Version:
71 lines (70 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateTimeType = void 0; const tslib_1 = require("tslib"); const valgen_1 = require("valgen"); const constants_js_1 = require("../../constants.js"); const simple_type_js_1 = require("../simple-type.js"); let DateTimeType = class DateTimeType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [constants_js_1.DECODER](properties) { const fn = valgen_1.vg.isDate({ precision: 'time', coerce: true }); const x = []; if (properties.minValue != null) { (0, valgen_1.isDateString)(properties.minValue); x.push(valgen_1.toString, valgen_1.vg.isGte(properties.minValue)); } if (properties.maxValue != null) { (0, valgen_1.isDateString)(properties.maxValue); x.push(valgen_1.toString, valgen_1.vg.isLte(properties.maxValue)); } return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn; } [constants_js_1.ENCODER](properties) { const fn = valgen_1.vg.isDateString({ precision: 'time', trim: 'time', coerce: true, }); const x = []; if (properties.minValue != null) { (0, valgen_1.isDateString)(properties.minValue); x.push(valgen_1.vg.isGte(properties.minValue)); } if (properties.maxValue != null) { (0, valgen_1.isDateString)(properties.maxValue); x.push(valgen_1.vg.isLte(properties.maxValue)); } return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn; } }; exports.DateTimeType = DateTimeType; tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Minimum value', }), tslib_1.__metadata("design:type", String) ], DateTimeType.prototype, "minValue", void 0); tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Maximum value', }), tslib_1.__metadata("design:type", String) ], DateTimeType.prototype, "maxValue", void 0); exports.DateTimeType = DateTimeType = tslib_1.__decorate([ ((0, simple_type_js_1.SimpleType)({ name: 'datetime', description: 'A full datetime value', nameMappings: { js: 'string', json: 'string', }, }) .Example('2021-04-18T22:30:15') .Example('2021-04-18 22:30:15') .Example('2021-04-18 22:30')), tslib_1.__metadata("design:paramtypes", [Object]) ], DateTimeType);