diff --git a/lib/config.coffee b/lib/config.coffee index 377da1e..3b255c5 100644 --- a/lib/config.coffee +++ b/lib/config.coffee @@ -65,6 +65,7 @@ options = { LOG_FORMAT : {type : 'string', default : 'simple'}, ACCESS_LOG_FORMAT : {type : 'string', default : ''}, MAX_CONCURRENT_REQUESTS : {type : 'int', default: 20}, + DATETIME_MILLISECONDS : {type: 'bool', default: true}, # XML configuration XML_RECOVER : {type : 'bool', default : false}, diff --git a/lib/device.js b/lib/device.js index cc5ff40..0e0904e 100644 --- a/lib/device.js +++ b/lib/device.js @@ -66,7 +66,8 @@ function sanitizeParameterValue(parameterValue) { break; case 'xsd:dateTime': if (typeof parameterValue[0] !== 'number') { - let v = parseInt(parameterValue[0]); + // Don't use parseInt because it reads date string as a number + let v = +parameterValue[0]; if (isNaN(v)) { v = Date.parse(parameterValue[0]); if (isNaN(v)) diff --git a/lib/session.coffee b/lib/session.coffee index 7c05c6b..b6974de 100644 --- a/lib/session.coffee +++ b/lib/session.coffee @@ -1013,25 +1013,31 @@ generateSetRpcRequest = (sessionContext) -> # Set values GPV_BATCH_SIZE = config.get('GPV_BATCH_SIZE', sessionContext.deviceId) + DATETIME_MILLISECONDS = config.get('DATETIME_MILLISECONDS', sessionContext.deviceId) parameterValues = [] syncState.spv.forEach((v, k) -> return if parameterValues.length >= GPV_BATCH_SIZE + syncState.spv.delete(k) attrs = sessionContext.deviceData.attributes.get(k) if (curVal = attrs.value?[1])? and attrs.writable?[1] val = v.slice() val[1] = curVal[1] if not val[1]? device.sanitizeParameterValue(val) + # Strip milliseconds + if val[1] == 'xsd:dateTime' and not DATETIME_MILLISECONDS and typeof val[0] == 'number' + val[0] -= val[0] % 1000 + if val[0] != curVal[0] or val[1] != curVal[1] parameterValues.push([k, val[0], val[1]]) - syncState.spv.delete(k) ) if parameterValues.length return { name: 'SetParameterValues' parameterList: ([p[0].join('.'), p[1], p[2]] for p in parameterValues) + DATETIME_MILLISECONDS: DATETIME_MILLISECONDS } # Download diff --git a/lib/soap.js b/lib/soap.js index 08e6b67..cfc359c 100644 --- a/lib/soap.js +++ b/lib/soap.js @@ -210,10 +210,13 @@ function SetParameterValues(xml, methodRequest) { for (const p of methodRequest.parameterList) { const pvs = paramList.node("ParameterValueStruct"); pvs.node("Name").text(p[0]); - if (p[2] === 'xsd:dateTime' && Number.isInteger(p[1])) - pvs.node("Value").attr({"xsi:type": p[2]}).text((new Date(p[1])).toISOString()); - else - pvs.node("Value").attr({"xsi:type": p[2]}).text(p[1]); + let val = p[1]; + if (p[2] === 'xsd:dateTime' && typeof val === 'number') { + val = (new Date(val)).toISOString(); + if (methodRequest.DATETIME_MILLISECONDS === false) + val = val.replace('.000', ''); + } + pvs.node("Value").attr({"xsi:type": p[2]}).text(val); } el.node("ParameterKey").text(methodRequest.parameterKey || "");