From 71bb2d4f28891cea4f255c0a313676dbf31062c2 Mon Sep 17 00:00:00 2001 From: Shweelan Samson Date: Wed, 17 Oct 2018 19:19:27 +0300 Subject: [PATCH] Add support for timestamp in smart query --- client/smart-query.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/smart-query.js b/client/smart-query.js index 50155f1..9bb432c 100644 --- a/client/smart-query.js +++ b/client/smart-query.js @@ -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);