提交 01fde397 编写于 作者: S StoneT2000

Fixed timestamp offset error and microsecond not displaying

上级 1cc50703
...@@ -17,7 +17,7 @@ function convertMillisecondsToDatetime(time) { ...@@ -17,7 +17,7 @@ function convertMillisecondsToDatetime(time) {
return new TaosObjects.TaosTimestamp(time); return new TaosObjects.TaosTimestamp(time);
} }
function convertMicrosecondsToDatetime(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) { function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false) {
......
...@@ -42,17 +42,32 @@ function TaosField(field) { ...@@ -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 * @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 { class TaosTimestamp extends Date {
constructor(date) { constructor(date, micro = false) {
super(date); super(date);
this._type = 'TaosTimestamp'; this._type = 'TaosTimestamp';
if (micro) {
this.microTime = date - Math.floor(date);
}
} }
/** /**
* @function Returns the date into a string usable by TDengine * @function Returns the date into a string usable by TDengine
* @return {string} A Taos Timestamp String * @return {string} A Taos Timestamp String
*/ */
toTaosString(){ toTaosString(){
let tsArr = this.toISOString().split("T") var tzo = -this.getTimezoneOffset(),
return tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1); 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);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册