@opra/common
Version:
Opra common package
86 lines (85 loc) • 3.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PartialDateType = 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 PartialDateType = class PartialDateType {
constructor(attributes) {
if (attributes)
Object.assign(this, attributes);
}
[constants_js_1.DECODER](properties) {
const fn = toPartialDate;
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 = toPartialDate;
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.PartialDateType = PartialDateType;
tslib_1.__decorate([
simple_type_js_1.SimpleType.Attribute({
description: 'Minimum value',
}),
tslib_1.__metadata("design:type", String)
], PartialDateType.prototype, "minValue", void 0);
tslib_1.__decorate([
simple_type_js_1.SimpleType.Attribute({
description: 'Maximum value',
}),
tslib_1.__metadata("design:type", String)
], PartialDateType.prototype, "maxValue", void 0);
exports.PartialDateType = PartialDateType = tslib_1.__decorate([
((0, simple_type_js_1.SimpleType)({
name: 'partialdate',
description: 'Specifies a point in time using a 24-hour clock notation.\rFormat: YYYY-[MM-[DD-[T?HH:[MM:[SS[.S[S[S[S]]]]]]]]][+/-ZZ:ZZ].',
nameMappings: {
js: 'string',
json: 'string',
},
})
.Example('2021-04-18T22:30:15:22+03:00')
.Example('2021-04-18 22:30')
.Example('2021-04-18')
.Example('2021')),
tslib_1.__metadata("design:paramtypes", [Object])
], PartialDateType);
const _isDateString = valgen_1.vg.isDateString({
precisionMin: 'year',
});
const toPartialDate = (0, valgen_1.validator)((input) => {
if (input instanceof Date) {
let s = _isDateString(input, { coerce: true });
if (s.endsWith('Z'))
s = s.substring(0, s.length - 1);
if (s.endsWith('.000'))
s = s.substring(0, s.length - 4);
if (s.endsWith(':00'))
s = s.substring(0, s.length - 3);
if (s.endsWith('00:00'))
s = s.substring(0, s.length - 6);
return s;
}
return _isDateString(input, { coerce: false });
});