提交 5a0cafa4 编写于 作者: L lihui

[#1096 TBASE-1389]

上级 19608988
......@@ -48,6 +48,7 @@ static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
extern int tsTscEnableRecordSql;
extern int tsNumOfLogLines;
void taosInitNote(int numOfNoteLines, int maxNotes, char* lable);
void deltaToUtcInitOnce();
void tscCheckDiskUsage(void *para, void *unused) {
taosGetDisk();
......@@ -60,6 +61,7 @@ void taos_init_imp() {
SRpcInit rpcInit;
srand(taosGetTimestampSec());
deltaToUtcInitOnce();
if (tscEmbedded == 0) {
/*
......
......@@ -42,6 +42,7 @@ int64_t taosGetTimestamp(int32_t precision);
int32_t getTimestampInUsFromStr(char* token, int32_t tokenlen, int64_t* ts);
int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec);
void deltaToUtcInitOnce();
#ifdef __cplusplus
}
......
......@@ -24,6 +24,61 @@
#include "ttime.h"
#include "tutil.h"
// ==== mktime() kernel code =================//
static int64_t m_deltaUtc = 0;
void deltaToUtcInitOnce() {
struct tm tm = {0};
(void)strptime("1970-01-01 00:00:00", (const char *)("%Y-%m-%d %H:%M:%S"), &tm);
m_deltaUtc = (int64_t)mktime(&tm);
//printf("====delta:%lld\n\n", seconds);
return;
}
int64_t user_mktime(struct tm * tm)
{
#define TAOS_MINUTE 60
#define TAOS_HOUR (60*TAOS_MINUTE)
#define TAOS_DAY (24*TAOS_HOUR)
#define TAOS_YEAR (365*TAOS_DAY)
static int month[12] = {
0,
TAOS_DAY*(31),
TAOS_DAY*(31+29),
TAOS_DAY*(31+29+31),
TAOS_DAY*(31+29+31+30),
TAOS_DAY*(31+29+31+30+31),
TAOS_DAY*(31+29+31+30+31+30),
TAOS_DAY*(31+29+31+30+31+30+31),
TAOS_DAY*(31+29+31+30+31+30+31+31),
TAOS_DAY*(31+29+31+30+31+30+31+31+30),
TAOS_DAY*(31+29+31+30+31+30+31+31+30+31),
TAOS_DAY*(31+29+31+30+31+30+31+31+30+31+30)
};
int64_t res;
int year;
year= tm->tm_year - 70;
res= TAOS_YEAR*year + TAOS_DAY*((year+1)/4);
res+= month[tm->tm_mon];
if(tm->tm_mon > 1 && ((year+2)%4)) {
res-= TAOS_DAY;
}
res+= TAOS_DAY*(tm->tm_mday-1);
res+= TAOS_HOUR*tm->tm_hour;
res+= TAOS_MINUTE*tm->tm_min;
res+= tm->tm_sec;
return res + m_deltaUtc;
}
static int64_t parseFraction(char* str, char** end, int32_t timePrec);
static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec);
static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec);
......@@ -238,6 +293,8 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
/* mktime will be affected by TZ, set by using taos_options */
int64_t seconds = mktime(&tm);
//int64_t seconds = (int64_t)user_mktime(&tm);
int64_t fraction = 0;
if (*str == '.') {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册