Add support for timestamp in smart query

This commit is contained in:
Shweelan Samson authored and Zaid Abdulla committed 2018-12-27 01:21:18 -08:00
1 parent 46c1781816
commit 71bb2d4f28
1 file changed
+21
+21
View File
@@ -63,6 +63,22 @@ function queryNumber(param, value) {
return [op, param, v];
}
function queryTimestamp(param, value) {
let op = "=";
for (const o of ["<>", "=", "<=", "<", ">=", ">"]) {
if (value.startsWith(o)) {
op = o;
value = value.slice(o.length).trim();
break;
}
}
let v = parseInt(value);
if (v !== +value) v = Date.parse(value);
if (isNaN(v)) return null;
return [op, param, v];
}
function queryString(param, value) {
return ["LIKE", ["FUNC", "LOWER", param], value.toLowerCase()];
}
@@ -105,6 +121,11 @@ function unpack(resource, label, value) {
if (q) res.push(q);
}
if (type.length === 0 || type.includes("timestamp")) {
const q = queryTimestamp(resources[resource][label].parameter, value);
if (q) res.push(q);
}
if (type.includes("mac")) {
const q = queryMac(resources[resource][label].parameter, value);
if (q) res.push(q);