@opra/common
Version:
Opra common package
77 lines (76 loc) • 2.46 kB
JavaScript
;
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");
const _isDateString = valgen_1.vg.isDateString({
precisionMin: 'day',
trim: 'tz',
coerce: true,
});
const _isDate = valgen_1.vg.isDate({
coerce: true,
});
let DateTimeType = class DateTimeType {
constructor(attributes) {
if (attributes)
Object.assign(this, attributes);
}
[constants_js_1.DECODER](properties) {
let fn;
if (properties.convertToNative) {
fn = _isDate;
}
else {
fn = _isDateString;
}
const x = [fn];
if (properties.minValue != null) {
x.push(valgen_1.vg.isGte(fn(properties.minValue)));
}
if (properties.maxValue != null) {
x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
}
return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn;
}
[constants_js_1.ENCODER](properties) {
const fn = _isDateString;
const x = [fn];
if (properties.minValue != null) {
x.push(valgen_1.vg.isGte(fn(properties.minValue)));
}
if (properties.maxValue != null) {
x.push(valgen_1.vg.isLte(fn(properties.maxValue)));
}
return x.length > 0 ? valgen_1.vg.pipe(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);