@dexpenses/rule-conditions
Version:
Condition engine and parser for Dexpenses rules
25 lines • 781 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function seconds(time) {
return time.hour * 60 * 60 + time.minute * 60 + (time.second || 0);
}
class TimeCondition {
constructor(threshold, type) {
this.threshold = seconds(threshold);
switch (type) {
case 'before':
this.cmp = (s) => s < this.threshold;
break;
case 'after':
this.cmp = (s) => s >= this.threshold;
break;
default:
throw new Error('unknown compare type: ' + type);
}
}
test(receipt) {
return !!receipt.time && this.cmp(seconds(receipt.time));
}
}
exports.default = TimeCondition;
//# sourceMappingURL=TimeCondition.js.map