Config to strip milliseconds from dateTime

This commit is contained in:
Zaid Abdulla committed 2017-11-12 12:29:18 -08:00
1 parent 6a9c62b639
commit f7c1857b6a
4 files changed
+17 -6

No files matched your search

+1
View File
@@ -65,6 +65,7 @@ options = {
LOG_FORMAT : {type : 'string', default : 'simple'}, LOG_FORMAT : {type : 'string', default : 'simple'},
ACCESS_LOG_FORMAT : {type : 'string', default : ''}, ACCESS_LOG_FORMAT : {type : 'string', default : ''},
MAX_CONCURRENT_REQUESTS : {type : 'int', default: 20}, MAX_CONCURRENT_REQUESTS : {type : 'int', default: 20},
DATETIME_MILLISECONDS : {type: 'bool', default: true},
# XML configuration # XML configuration
XML_RECOVER : {type : 'bool', default : false}, XML_RECOVER : {type : 'bool', default : false},
+2 -1
View File
@@ -66,7 +66,8 @@ function sanitizeParameterValue(parameterValue) {
break; break;
case 'xsd:dateTime': case 'xsd:dateTime':
if (typeof parameterValue[0] !== 'number') { 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)) { if (isNaN(v)) {
v = Date.parse(parameterValue[0]); v = Date.parse(parameterValue[0]);
if (isNaN(v)) if (isNaN(v))
+7 -1
View File
@@ -1013,25 +1013,31 @@ generateSetRpcRequest = (sessionContext) ->
# Set values # Set values
GPV_BATCH_SIZE = config.get('GPV_BATCH_SIZE', sessionContext.deviceId) GPV_BATCH_SIZE = config.get('GPV_BATCH_SIZE', sessionContext.deviceId)
DATETIME_MILLISECONDS = config.get('DATETIME_MILLISECONDS', sessionContext.deviceId)
parameterValues = [] parameterValues = []
syncState.spv.forEach((v, k) -> syncState.spv.forEach((v, k) ->
return if parameterValues.length >= GPV_BATCH_SIZE return if parameterValues.length >= GPV_BATCH_SIZE
syncState.spv.delete(k)
attrs = sessionContext.deviceData.attributes.get(k) attrs = sessionContext.deviceData.attributes.get(k)
if (curVal = attrs.value?[1])? and attrs.writable?[1] if (curVal = attrs.value?[1])? and attrs.writable?[1]
val = v.slice() val = v.slice()
val[1] = curVal[1] if not val[1]? val[1] = curVal[1] if not val[1]?
device.sanitizeParameterValue(val) 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] if val[0] != curVal[0] or val[1] != curVal[1]
parameterValues.push([k, val[0], val[1]]) parameterValues.push([k, val[0], val[1]])
syncState.spv.delete(k)
) )
if parameterValues.length if parameterValues.length
return { return {
name: 'SetParameterValues' name: 'SetParameterValues'
parameterList: ([p[0].join('.'), p[1], p[2]] for p in parameterValues) parameterList: ([p[0].join('.'), p[1], p[2]] for p in parameterValues)
DATETIME_MILLISECONDS: DATETIME_MILLISECONDS
} }
# Download # Download
+7 -4
View File
@@ -210,10 +210,13 @@ function SetParameterValues(xml, methodRequest) {
for (const p of methodRequest.parameterList) { for (const p of methodRequest.parameterList) {
const pvs = paramList.node("ParameterValueStruct"); const pvs = paramList.node("ParameterValueStruct");
pvs.node("Name").text(p[0]); pvs.node("Name").text(p[0]);
if (p[2] === 'xsd:dateTime' && Number.isInteger(p[1])) let val = p[1];
pvs.node("Value").attr({"xsi:type": p[2]}).text((new Date(p[1])).toISOString()); if (p[2] === 'xsd:dateTime' && typeof val === 'number') {
else val = (new Date(val)).toISOString();
pvs.node("Value").attr({"xsi:type": p[2]}).text(p[1]); 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 || ""); el.node("ParameterKey").text(methodRequest.parameterKey || "");