fh1ch / node-bacstack

A BACnet protocol stack written in pure JavaScript
MIT License
170 stars 97 forks source link

fix date value for event time stamps #178

Open cdriks opened 1 year ago

cdriks commented 1 year ago

Hi,

by performing a readProperty to property 130 (event-time-stamps), the returned value is seen as "Invalid Date".

Steps to reproduce Issue (Bug Report)

const bacstack = require('bacstack');

const client = new bacstack()

client.readProperty('10.12.44.11', { type: 2, instance: 8194 }, 130, (err, value) => {
    console.log(err)
    console.log(JSON.stringify(value.values))
    console.log(value.values)
})

returns :

[
  { type: 104, value: Invalid Date },
  { type: 104, value: Invalid Date },
  { type: 104, value: Invalid Date }
]

The cause from this can be found at asn1.js, line 1000.

The date variable has the following value : {"len":5,"value":{"len":4,"value":"2022-10-26T22:00:00.000Z"}}, and the time : {"len":5,"value":{"len":4,"value":"1901-02-01T15:26:22.600Z"}}

What does this Pull Request do

After the correction, the result of the above-mentioned command is :

[
  { type: 104, value: 2022-09-27T14:26:22.600Z },
  { type: 104, value: 1900-12-31T23:00:00.000Z },
  { type: 104, value: 2022-09-27T15:34:59.800Z }
]

There, the second item of the array is not completely correct (it should be unspecified), but it makes the job...

Thanks in advance,

Cédric