From 01fde397061424bafa585d24fa93da53dea0323a Mon Sep 17 00:00:00 2001 From: StoneT2000 Date: Tue, 15 Oct 2019 02:09:00 -0700 Subject: [PATCH] Fixed timestamp offset error and microsecond not displaying --- src/connector/nodejs/nodetaos/cinterface.js | 2 +- src/connector/nodejs/nodetaos/taosobjects.js | 21 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/connector/nodejs/nodetaos/cinterface.js b/src/connector/nodejs/nodetaos/cinterface.js index 8fe7d8673c..a8183e1d45 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) { diff --git a/src/connector/nodejs/nodetaos/taosobjects.js b/src/connector/nodejs/nodetaos/taosobjects.js index 2894fb8147..42d9f8407c 100644 --- a/src/connector/nodejs/nodetaos/taosobjects.js +++ b/src/connector/nodejs/nodetaos/taosobjects.js @@ -42,17 +42,32 @@ 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; + }; + return this.getFullYear() + + '-' + pad(this.getMonth() + 1) + + '-' + pad(this.getDate()) + + ' ' + pad(this.getHours()) + + ':' + pad(this.getMinutes()) + + ':' + pad(this.getSeconds()) + + '.' + pad(this.getMilliseconds()) + + '' + (this.microTime ? this.microTime.toFixed(3) : '').substr(2); } } -- GitLab