Display xsd:dateTime types as ISO string

This commit is contained in:
Zaid Abdulla committed 2021-01-31 11:39:02 -08:00
1 parent ca36bf1b64
commit 1e6ab38ede
3 files changed
+30 -9

No files matched your search

+22 -3
View File
@@ -106,14 +106,23 @@ router.get(`/devices/:id.csv`, async (ctx) => {
for (const k of Object.keys(res[0]).sort()) { for (const k of Object.keys(res[0]).sort()) {
const p = res[0][k]; const p = res[0][k];
let value = "";
let type = "";
if (p.value) {
value = p.value[0];
type = p.value[1];
if (type === "xsd:dateTime" && typeof value === "number")
value = new Date(value).toJSON();
}
const row = [ const row = [
k, k,
p.object, p.object,
p.objectTimestamp, p.objectTimestamp,
p.writable, p.writable,
p.writableTimestamp, p.writableTimestamp,
p.value != null ? `"${p.value[0].toString().replace(/"/g, '""')}"` : "", `"${value.toString().replace(/"/g, '""')}"`,
p.value != null ? p.value[1] : "", type,
p.valueTimestamp, p.valueTimestamp,
p.notification, p.notification,
p.notificationTimestamp, p.notificationTimestamp,
@@ -285,11 +294,21 @@ for (const [resource, flags] of Object.entries(resources)) {
return tags.join(", "); return tags.join(", ");
} }
if (e === exp) {
const p = obj[e[1]];
if (
p &&
p.value &&
p.value[1] === "xsd:dateTime" &&
typeof p.value[0] === "number"
)
return new Date(p.value[0]).toJSON();
}
} }
} else if (e[0] === "FUNC") { } else if (e[0] === "FUNC") {
if (e[1] === "DATE_STRING") { if (e[1] === "DATE_STRING") {
if (e[2] && !Array.isArray(e[2])) if (e[2] && !Array.isArray(e[2]))
return new Date(e[2]).toISOString(); return new Date(e[2]).toJSON();
} }
} }
} }
+2
View File
@@ -62,6 +62,8 @@ const evaluateParam = memoize((exp, obj, now: number) => {
timestamp = p.valueTimestamp; timestamp = p.valueTimestamp;
value = p.value[0]; value = p.value[0];
parameter = exp[1]; parameter = exp[1];
if (p.value[1] === "xsd:dateTime" && typeof value === "number")
value = new Date(value).toLocaleString();
} }
} }
+6 -6
View File
@@ -76,13 +76,13 @@ function renderStagingSpv(task: StageTask, queueFunc, cancelFunc): Children {
] ]
); );
} else { } else {
const type = task.parameterValues[0][2];
let value = task.parameterValues[0][1];
if (type === "xsd:dateTime" && typeof value === "number")
value = new Date(value).toJSON() || value;
input = m("input", { input = m("input", {
type: ["xsd:dateTime", "xsd:int", "xsd:unsignedInt"].includes( type: ["xsd:int", "xsd:unsignedInt"].includes(type) ? "number" : "text",
task.parameterValues[0][2] value: value,
)
? "number"
: "text",
value: task.parameterValues[0][1],
oninput: (e) => { oninput: (e) => {
e.redraw = false; e.redraw = false;
task.parameterValues[0][1] = input.dom.value; task.parameterValues[0][1] = input.dom.value;