提交 c571c38b 编写于 作者: S slguan

revise issue #124

上级 0da8e9ad
......@@ -63,8 +63,8 @@ void httpJsonString(JsonBuf* buf, char* sVal, int len);
void httpJsonOriginString(JsonBuf* buf, char* sVal, int len);
void httpJsonStringForTransMean(JsonBuf* buf, char* SVal, int maxLen);
void httpJsonInt64(JsonBuf* buf, int64_t num);
void httpJsonTimestamp(JsonBuf* buf, int64_t t);
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t);
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us);
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us);
void httpJsonInt(JsonBuf* buf, int num);
void httpJsonFloat(JsonBuf* buf, float num);
void httpJsonDouble(JsonBuf* buf, double num);
......
......@@ -40,8 +40,8 @@
#define REST_JSON_AFFECT_ROWS_LEN 13
#define REST_TIMESTAMP_FMT_LOCAL_STRING 0
#define REST_TIMESTAMP_FMT_TIMESTAMP 1
#define REST_TIMESTAMP_FMT_UTC_STRING 2
#define REST_TIMESTAMP_FMT_TIMESTAMP 1
#define REST_TIMESTAMP_FMT_UTC_STRING 2
void restBuildSqlAffectRowsJson(HttpContext *pContext, HttpSqlCmd *cmd, int affect_rows);
......
......@@ -260,30 +260,45 @@ void httpJsonInt64(JsonBuf* buf, int64_t num) {
buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%ld", num);
}
void httpJsonTimestamp(JsonBuf* buf, int64_t t) {
char ts[30] = {0};
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
char ts[35] = {0};
struct tm *ptm;
int precision = 1000;
if (us) {
precision = 1000000;
}
struct tm* ptm;
time_t tt = t / 1000;
time_t tt = t / precision;
ptm = localtime(&tt);
int length = (int)strftime(ts, 30, "%Y-%m-%d %H:%M:%S", ptm);
snprintf(ts+length, MAX_NUM_STR_SZ, ".%03ld", t % 1000);
int length = (int) strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm);
if (us) {
length += snprintf(ts + length, 8, ".%06ld", t % precision);
} else {
length += snprintf(ts + length, 5, ".%03ld", t % precision);
}
httpJsonString(buf, ts, length + 4);
httpJsonString(buf, ts, length);
}
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t) {
char ts[35] = {0};
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us) {
char ts[40] = {0};
struct tm *ptm;
time_t tt = t / 1000;
int precision = 1000;
if (us) {
precision = 1000000;
}
time_t tt = t / precision;
ptm = localtime(&tt);
int length = (int) strftime(ts, 35, "%Y-%m-%dT%H:%M:%S", ptm);
length += snprintf(ts + length, MAX_NUM_STR_SZ, ".%03ld", t % 1000);
length += (int) strftime(ts + length, 35 - length, "%z", ptm);
int length = (int) strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm);
if (us) {
length += snprintf(ts + length, 8, ".%06ld", t % precision);
} else {
length += snprintf(ts + length, 5, ".%03ld", t % precision);
}
length += (int) strftime(ts + length, 40 - length, "%z", ptm);
httpJsonString(buf, ts, length + 4);
httpJsonString(buf, ts, length);
}
void httpJsonInt(JsonBuf* buf, int num) {
......
......@@ -135,11 +135,11 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
break;
case TSDB_DATA_TYPE_TIMESTAMP:
if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) {
httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]));
httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO);
} else if (timestampFormat == REST_TIMESTAMP_FMT_TIMESTAMP) {
httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
} else {
httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]));
httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO);
}
break;
default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册