UNPKG

@opra/common

Version:
53 lines (52 loc) 1.81 kB
import { __decorate, __metadata } from "tslib"; import { vg } from 'valgen'; import { DECODER, ENCODER } from '../../constants.js'; import { SimpleType } from '../simple-type.js'; let DateTimeStringType = class DateTimeStringType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [DECODER](properties) { const fn = vg.isDateString({ coerce: true }); const x = []; if (properties.minValue != null) x.push(vg.isGte(properties.minValue)); if (properties.maxValue != null) x.push(vg.isLte(properties.maxValue)); return x.length > 0 ? vg.pipe([fn, ...x]) : fn; } [ENCODER](properties) { return this[DECODER](properties); } }; __decorate([ SimpleType.Attribute({ description: 'Minimum value', }), __metadata("design:type", String) ], DateTimeStringType.prototype, "minValue", void 0); __decorate([ SimpleType.Attribute({ description: 'Maximum value', }), __metadata("design:type", String) ], DateTimeStringType.prototype, "maxValue", void 0); DateTimeStringType = __decorate([ (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')), __metadata("design:paramtypes", [Object]) ], DateTimeStringType); export { DateTimeStringType };