Fix date parsing in flattenDevice
This commit is contained in:
1 parent
4e378d4dff
commit
18c31ae934
1 file changed
+9
-4
@@ -208,13 +208,18 @@ function processDeviceSort(sort) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDate(d) {
|
||||||
|
const n = +d;
|
||||||
|
return isNaN(n) ? "" + d : n;
|
||||||
|
}
|
||||||
|
|
||||||
function flattenDevice(device) {
|
function flattenDevice(device) {
|
||||||
function recursive(input, root, output, timestamp) {
|
function recursive(input, root, output, timestamp) {
|
||||||
for (const [name, tree] of Object.entries(input)) {
|
for (const [name, tree] of Object.entries(input)) {
|
||||||
if (!root) {
|
if (!root) {
|
||||||
if (name === "_lastInform") {
|
if (name === "_lastInform") {
|
||||||
output["Events.Inform"] = {
|
output["Events.Inform"] = {
|
||||||
value: [Date.parse(tree), "xsd:dateTime"],
|
value: [parseDate(tree), "xsd:dateTime"],
|
||||||
valueTimestamp: timestamp,
|
valueTimestamp: timestamp,
|
||||||
writable: false,
|
writable: false,
|
||||||
writableTimestamp: timestamp,
|
writableTimestamp: timestamp,
|
||||||
@@ -223,7 +228,7 @@ function flattenDevice(device) {
|
|||||||
};
|
};
|
||||||
} else if (name === "_registered") {
|
} else if (name === "_registered") {
|
||||||
output["Events.Registered"] = {
|
output["Events.Registered"] = {
|
||||||
value: [Date.parse(tree), "xsd:dateTime"],
|
value: [parseDate(tree), "xsd:dateTime"],
|
||||||
valueTimestamp: timestamp,
|
valueTimestamp: timestamp,
|
||||||
writable: false,
|
writable: false,
|
||||||
writableTimestamp: timestamp,
|
writableTimestamp: timestamp,
|
||||||
@@ -232,7 +237,7 @@ function flattenDevice(device) {
|
|||||||
};
|
};
|
||||||
} else if (name === "_lastBoot") {
|
} else if (name === "_lastBoot") {
|
||||||
output["Events.1_BOOT"] = {
|
output["Events.1_BOOT"] = {
|
||||||
value: [Date.parse(tree), "xsd:dateTime"],
|
value: [parseDate(tree), "xsd:dateTime"],
|
||||||
valueTimestamp: timestamp,
|
valueTimestamp: timestamp,
|
||||||
writable: false,
|
writable: false,
|
||||||
writableTimestamp: timestamp,
|
writableTimestamp: timestamp,
|
||||||
@@ -241,7 +246,7 @@ function flattenDevice(device) {
|
|||||||
};
|
};
|
||||||
} else if (name === "_lastBootstrap") {
|
} else if (name === "_lastBootstrap") {
|
||||||
output["Events.0_BOOTSTRAP"] = {
|
output["Events.0_BOOTSTRAP"] = {
|
||||||
value: [Date.parse(tree), "xsd:dateTime"],
|
value: [parseDate(tree), "xsd:dateTime"],
|
||||||
valueTimestamp: timestamp,
|
valueTimestamp: timestamp,
|
||||||
writable: false,
|
writable: false,
|
||||||
writableTimestamp: timestamp,
|
writableTimestamp: timestamp,
|
||||||
|
|||||||
Reference in new issue
Block a user