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'},
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},
+2 -1
View File
@@ -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))
+7 -1
View File
@@ -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
+7 -4
View File
@@ -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 || "");