diff --git a/src/connector/nodejs/nodetaos/cinterface.js b/src/connector/nodejs/nodetaos/cinterface.js index 8fe7d8673c..2b409268d9 100644 --- a/src/connector/nodejs/nodetaos/cinterface.js +++ b/src/connector/nodejs/nodetaos/cinterface.js @@ -17,7 +17,7 @@ function convertMillisecondsToDatetime(time) { return new TaosObjects.TaosTimestamp(time); } function convertMicrosecondsToDatetime(time) { - return new TaosObjects.TaosTimestamp(time * 0.001); + return new TaosObjects.TaosTimestamp(time * 0.001, true); } function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { @@ -33,9 +33,6 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false let time = 0; for (let i = currOffset; i < currOffset + nbytes; i++) { queue.push(data[i]); - if (data[i] == 0) { - break; - } } for (let i = queue.length - 1; i >= 0; i--) { time += queue[i] * Math.pow(16, i * 2); diff --git a/src/connector/nodejs/nodetaos/taosobjects.js b/src/connector/nodejs/nodetaos/taosobjects.js index 2894fb8147..809d17a016 100644 --- a/src/connector/nodejs/nodetaos/taosobjects.js +++ b/src/connector/nodejs/nodetaos/taosobjects.js @@ -42,17 +42,38 @@ function TaosField(field) { * @param {Date} date - A Javascript date time object or the time in milliseconds past 1970-1-1 00:00:00.000 */ class TaosTimestamp extends Date { - constructor(date) { + constructor(date, micro = false) { super(date); this._type = 'TaosTimestamp'; + if (micro) { + this.microTime = date - Math.floor(date); + } } /** * @function Returns the date into a string usable by TDengine * @return {string} A Taos Timestamp String */ toTaosString(){ - let tsArr = this.toISOString().split("T") - return tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1); + var tzo = -this.getTimezoneOffset(), + dif = tzo >= 0 ? '+' : '-', + pad = function(num) { + var norm = Math.floor(Math.abs(num)); + return (norm < 10 ? '0' : '') + norm; + }, + pad2 = function(num) { + var norm = Math.floor(Math.abs(num)); + if (norm < 10) return '00' + norm; + if (norm < 100) return '0' + norm; + if (norm < 1000) return norm; + }; + return this.getFullYear() + + '-' + pad(this.getMonth() + 1) + + '-' + pad(this.getDate()) + + ' ' + pad(this.getHours()) + + ':' + pad(this.getMinutes()) + + ':' + pad(this.getSeconds()) + + '.' + pad2(this.getMilliseconds()) + + '' + (this.microTime ? pad2(Math.round(this.microTime * 1000)) : ''); } } diff --git a/src/connector/nodejs/package-lock.json b/src/connector/nodejs/package-lock.json index 3e3d55a32b..ab7789f7c6 100644 --- a/src/connector/nodejs/package-lock.json +++ b/src/connector/nodejs/package-lock.json @@ -1,6 +1,6 @@ { "name": "td-connector", - "version": "1.3.2", + "version": "1.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/connector/nodejs/package.json b/src/connector/nodejs/package.json index 856c56361b..7f42d40a91 100644 --- a/src/connector/nodejs/package.json +++ b/src/connector/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "td-connector", - "version": "1.3.2", + "version": "1.5.0", "description": "A Node.js connector for TDengine.", "main": "tdengine.js", "scripts": {