UNPKG

@opra/common

Version:
56 lines (55 loc) 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateTimeStringType = 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 DateTimeStringType = class DateTimeStringType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [constants_js_1.DECODER](properties) { const fn = valgen_1.vg.isDateString({ coerce: true }); const x = []; if (properties.minValue != null) x.push(valgen_1.vg.isGte(properties.minValue)); if (properties.maxValue != null) x.push(valgen_1.vg.isLte(properties.maxValue)); return x.length > 0 ? valgen_1.vg.pipe([fn, ...x]) : fn; } [constants_js_1.ENCODER](properties) { return this[constants_js_1.DECODER](properties); } }; exports.DateTimeStringType = DateTimeStringType; tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Minimum value', }), tslib_1.__metadata("design:type", String) ], DateTimeStringType.prototype, "minValue", void 0); tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Maximum value', }), tslib_1.__metadata("design:type", String) ], DateTimeStringType.prototype, "maxValue", void 0); exports.DateTimeStringType = DateTimeStringType = tslib_1.__decorate([ ((0, simple_type_js_1.SimpleType)({ name: 'datetimestring', description: 'DateTime string value', nameMappings: { js: 'string', json: 'string', }, }) .Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone') .Example('2021-04-18T22:30:15', 'Full date-time value without timezone') .Example('2021-04-18 22:30', 'Date-time value') .Example('2021-04-18', 'Date value') .Example('2021-04', 'Date value without day') .Example('2021', 'Year only value')), tslib_1.__metadata("design:paramtypes", [Object]) ], DateTimeStringType);