UNPKG

@opra/common

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