[TD-13772]<fix>: add timezone enum.
This commit is contained in:
parent
ed308f451f
commit
c712e581b3
|
@ -75,7 +75,6 @@ extern "C" {
|
||||||
#include "osDef.h"
|
#include "osDef.h"
|
||||||
#include "osDir.h"
|
#include "osDir.h"
|
||||||
#include "osEndian.h"
|
#include "osEndian.h"
|
||||||
#include "osEnv.h"
|
|
||||||
#include "osFile.h"
|
#include "osFile.h"
|
||||||
#include "osLocale.h"
|
#include "osLocale.h"
|
||||||
#include "osLz4.h"
|
#include "osLz4.h"
|
||||||
|
@ -93,8 +92,9 @@ extern "C" {
|
||||||
#include "osTime.h"
|
#include "osTime.h"
|
||||||
#include "osTimer.h"
|
#include "osTimer.h"
|
||||||
#include "osTimezone.h"
|
#include "osTimezone.h"
|
||||||
|
#include "osEnv.h"
|
||||||
|
|
||||||
void osInit();
|
void osDefaultInit();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,17 +22,18 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char tsOsName[];
|
extern char tsOsName[];
|
||||||
extern char tsTimezone[];
|
extern char tsTimezoneStr[];
|
||||||
extern char tsCharset[];
|
extern enum TdTimezone tsTimezone;
|
||||||
extern char tsLocale[];
|
extern char tsCharset[];
|
||||||
extern int8_t tsDaylight;
|
extern char tsLocale[];
|
||||||
extern bool tsEnableCoreFile;
|
extern int8_t tsDaylight;
|
||||||
extern int64_t tsPageSizeKB;
|
extern bool tsEnableCoreFile;
|
||||||
extern int64_t tsOpenMax;
|
extern int64_t tsPageSizeKB;
|
||||||
extern int64_t tsStreamMax;
|
extern int64_t tsOpenMax;
|
||||||
extern float tsNumOfCores;
|
extern int64_t tsStreamMax;
|
||||||
extern int64_t tsTotalMemoryKB;
|
extern float tsNumOfCores;
|
||||||
|
extern int64_t tsTotalMemoryKB;
|
||||||
|
|
||||||
extern char configDir[];
|
extern char configDir[];
|
||||||
extern char tsDataDir[];
|
extern char tsDataDir[];
|
||||||
|
@ -43,11 +44,12 @@ extern SDiskSpace tsDataSpace;
|
||||||
extern SDiskSpace tsLogSpace;
|
extern SDiskSpace tsLogSpace;
|
||||||
extern SDiskSpace tsTempSpace;
|
extern SDiskSpace tsTempSpace;
|
||||||
|
|
||||||
void osInit();
|
void osDefaultInit();
|
||||||
void osUpdate();
|
void osUpdate();
|
||||||
void osCleanup();
|
void osCleanup();
|
||||||
bool osLogSpaceAvailable();
|
bool osLogSpaceAvailable();
|
||||||
void osSetTimezone(const char *timezone);
|
void osSetTimezone(const char *timezone);
|
||||||
|
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,37 @@ extern "C" {
|
||||||
#define tzset TZSET_FUNC_TAOS_FORBID
|
#define tzset TZSET_FUNC_TAOS_FORBID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void taosGetSystemTimezone(char *outTimezone);
|
enum TdTimezone
|
||||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight);
|
{
|
||||||
|
TdWestZone12=-12,
|
||||||
|
TdWestZone11,
|
||||||
|
TdWestZone10,
|
||||||
|
TdWestZone9,
|
||||||
|
TdWestZone8,
|
||||||
|
TdWestZone7,
|
||||||
|
TdWestZone6,
|
||||||
|
TdWestZone5,
|
||||||
|
TdWestZone4,
|
||||||
|
TdWestZone3,
|
||||||
|
TdWestZone2,
|
||||||
|
TdWestZone1,
|
||||||
|
TdZeroZero,
|
||||||
|
TdEastZone1,
|
||||||
|
TdEastZone2,
|
||||||
|
TdEastZone3,
|
||||||
|
TdEastZone4,
|
||||||
|
TdEastZone5,
|
||||||
|
TdEastZone6,
|
||||||
|
TdEastZone7,
|
||||||
|
TdEastZone8,
|
||||||
|
TdEastZone9,
|
||||||
|
TdEastZone10,
|
||||||
|
TdEastZone11,
|
||||||
|
TdEastZone12
|
||||||
|
};
|
||||||
|
|
||||||
|
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
|
||||||
|
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,10 +408,10 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
||||||
assert(cfg != NULL);
|
assert(cfg != NULL);
|
||||||
|
|
||||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||||
tstrncpy(tsTimezone, str, TD_TIMEZONE_LEN);
|
tstrncpy(tsTimezoneStr, str, TD_TIMEZONE_LEN);
|
||||||
tsSetTimeZone();
|
tsSetTimeZone();
|
||||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str);
|
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezoneStr, str);
|
||||||
} else {
|
} else {
|
||||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str,
|
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str,
|
||||||
tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||||
|
|
|
@ -303,7 +303,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
||||||
static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
||||||
SysNameInfo info = taosGetSysNameInfo();
|
SysNameInfo info = taosGetSysNameInfo();
|
||||||
|
|
||||||
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
|
if (cfgAddTimezone(pCfg, "timezone", tsTimezoneStr) != 0) return -1;
|
||||||
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
|
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
|
||||||
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
|
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
|
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
|
||||||
|
@ -431,12 +431,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
||||||
static void taosSetSystemCfg(SConfig *pCfg) {
|
static void taosSetSystemCfg(SConfig *pCfg) {
|
||||||
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
|
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
|
||||||
osSetTimezone(pItem->str);
|
osSetTimezone(pItem->str);
|
||||||
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezone);
|
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr);
|
||||||
cfgSetItem(pCfg, "timezone", tsTimezone, pItem->stype);
|
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype);
|
||||||
|
|
||||||
const char *locale = cfgGetItem(pCfg, "locale")->str;
|
const char *locale = cfgGetItem(pCfg, "locale")->str;
|
||||||
const char *charset = cfgGetItem(pCfg, "charset")->str;
|
const char *charset = cfgGetItem(pCfg, "charset")->str;
|
||||||
taosSetSystemLocale(locale, charset);
|
taosSetSystemLocale(locale, charset);
|
||||||
|
osSetSystemLocale(locale, charset);
|
||||||
|
|
||||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||||
taosSetConsoleEcho(enableCore);
|
taosSetConsoleEcho(enableCore);
|
||||||
|
@ -483,7 +484,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
|
|
||||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||||
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||||
osInit();
|
osDefaultInit();
|
||||||
|
|
||||||
SConfig *pCfg = cfgInit();
|
SConfig *pCfg = cfgInit();
|
||||||
if (pCfg == NULL) return -1;
|
if (pCfg == NULL) return -1;
|
||||||
|
|
|
@ -36,7 +36,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
||||||
req.clusterCfg.checkTime = 0;
|
req.clusterCfg.checkTime = 0;
|
||||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||||
memcpy(req.clusterCfg.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||||
taosRUnLockLatch(&pMgmt->latch);
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
|
|
|
@ -277,8 +277,8 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
|
||||||
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
|
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((0 != strcasecmp(pCfg->timezone, tsTimezone)) && (pMnode->checkTime != pCfg->checkTime)) {
|
if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) {
|
||||||
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezone,
|
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr,
|
||||||
pCfg->checkTime, pMnode->checkTime);
|
pCfg->checkTime, pMnode->checkTime);
|
||||||
return DND_REASON_TIME_ZONE_NOT_MATCH;
|
return DND_REASON_TIME_ZONE_NOT_MATCH;
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, i
|
||||||
totalRows++;
|
totalRows++;
|
||||||
|
|
||||||
cfgOpts[totalRows] = "timezone";
|
cfgOpts[totalRows] = "timezone";
|
||||||
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone);
|
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr);
|
||||||
totalRows++;
|
totalRows++;
|
||||||
|
|
||||||
cfgOpts[totalRows] = "locale";
|
cfgOpts[totalRows] = "locale";
|
||||||
|
|
|
@ -176,7 +176,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// record current timezone of server side
|
// record current timezone of server side
|
||||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||||
|
|
||||||
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
|
|
|
@ -18,30 +18,31 @@
|
||||||
|
|
||||||
extern void taosWinSocketInit();
|
extern void taosWinSocketInit();
|
||||||
|
|
||||||
char configDir[PATH_MAX] = {0};
|
char configDir[PATH_MAX] = {0};
|
||||||
char tsDataDir[PATH_MAX] = {0};
|
char tsDataDir[PATH_MAX] = {0};
|
||||||
char tsLogDir[PATH_MAX] = {0};
|
char tsLogDir[PATH_MAX] = {0};
|
||||||
char tsTempDir[PATH_MAX] = {0};
|
char tsTempDir[PATH_MAX] = {0};
|
||||||
SDiskSpace tsDataSpace = {0};
|
SDiskSpace tsDataSpace = {0};
|
||||||
SDiskSpace tsLogSpace = {0};
|
SDiskSpace tsLogSpace = {0};
|
||||||
SDiskSpace tsTempSpace = {0};
|
SDiskSpace tsTempSpace = {0};
|
||||||
char tsOsName[16] = {0};
|
char tsOsName[16] = {0};
|
||||||
char tsTimezone[TD_TIMEZONE_LEN] = {0};
|
char tsTimezoneStr[TD_TIMEZONE_LEN] = {0};
|
||||||
char tsLocale[TD_LOCALE_LEN] = {0};
|
enum TdTimezone tsTimezone = TdZeroZero;
|
||||||
char tsCharset[TD_CHARSET_LEN] = {0};
|
char tsLocale[TD_LOCALE_LEN] = {0};
|
||||||
int8_t tsDaylight = 0;
|
char tsCharset[TD_CHARSET_LEN] = {0};
|
||||||
bool tsEnableCoreFile = 0;
|
int8_t tsDaylight = 0;
|
||||||
int64_t tsPageSizeKB = 0;
|
bool tsEnableCoreFile = 0;
|
||||||
int64_t tsOpenMax = 0;
|
int64_t tsPageSizeKB = 0;
|
||||||
int64_t tsStreamMax = 0;
|
int64_t tsOpenMax = 0;
|
||||||
float tsNumOfCores = 0;
|
int64_t tsStreamMax = 0;
|
||||||
int64_t tsTotalMemoryKB = 0;
|
float tsNumOfCores = 0;
|
||||||
|
int64_t tsTotalMemoryKB = 0;
|
||||||
|
|
||||||
void osInit() {
|
void osDefaultInit() {
|
||||||
taosSeedRand(taosSafeRand());
|
taosSeedRand(taosSafeRand());
|
||||||
taosGetSystemLocale(tsLocale, tsCharset);
|
taosGetSystemLocale(tsLocale, tsCharset);
|
||||||
taosGetSystemTimezone(tsTimezone);
|
taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
|
||||||
taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight);
|
taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
|
||||||
taosGetSystemInfo();
|
taosGetSystemInfo();
|
||||||
|
|
||||||
// deadlock in query
|
// deadlock in query
|
||||||
|
@ -105,4 +106,9 @@ void osCleanup() {}
|
||||||
|
|
||||||
bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; }
|
bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; }
|
||||||
|
|
||||||
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); }
|
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, tsTimezoneStr, &tsDaylight, &tsTimezone); }
|
||||||
|
|
||||||
|
void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
|
||||||
|
memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
|
||||||
|
memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
|
||||||
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
#define ALLOW_FORBID_FUNC
|
#define ALLOW_FORBID_FUNC
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#define USE_TD_MEMORY
|
|
||||||
|
|
||||||
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
|
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
|
||||||
|
|
||||||
#define TD_MEMORY_STACK_TRACE_DEPTH 10
|
#define TD_MEMORY_STACK_TRACE_DEPTH 10
|
||||||
|
@ -47,16 +45,16 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
|
||||||
int32_t frame = 0;
|
int32_t frame = 0;
|
||||||
void **ebp;
|
void **ebp;
|
||||||
void **ret = NULL;
|
void **ret = NULL;
|
||||||
unsigned long long func_frame_distance = 0;
|
size_t func_frame_distance = 0;
|
||||||
if (buffer != NULL && size > 0) {
|
if (buffer != NULL && size > 0) {
|
||||||
ebp = taosGetEbp();
|
ebp = taosGetEbp();
|
||||||
func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp;
|
func_frame_distance = (size_t)*ebp - (size_t)ebp;
|
||||||
while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) // assume function ebp more than 16M
|
while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) // assume function ebp more than 16M
|
||||||
&& (func_frame_distance > 0)) {
|
&& (func_frame_distance > 0)) {
|
||||||
ret = ebp + 1;
|
ret = ebp + 1;
|
||||||
buffer[frame++] = *ret;
|
buffer[frame++] = *ret;
|
||||||
ebp = (void **)(*ebp);
|
ebp = (void **)(*ebp);
|
||||||
func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp;
|
func_frame_distance = (size_t)*ebp - (size_t)ebp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return frame;
|
return frame;
|
||||||
|
|
|
@ -46,12 +46,22 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) {
|
void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight, enum TdTimezone *tsTimezone) {
|
||||||
if (inTimezone == NULL || inTimezone[0] == 0) return;
|
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) return;
|
||||||
|
|
||||||
|
char *buf = taosMemoryMalloc(strlen(inTimezoneStr) + 1);
|
||||||
|
buf[strlen(inTimezoneStr)] = 0;
|
||||||
|
for (int32_t i = 0; i < strlen(inTimezoneStr); i++) {
|
||||||
|
if(inTimezoneStr[i]==' ' || inTimezoneStr[i]=='(') {
|
||||||
|
buf[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf[i] = inTimezoneStr[i];
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
char winStr[TD_LOCALE_LEN * 2];
|
char winStr[TD_LOCALE_LEN * 2];
|
||||||
sprintf(winStr, "TZ=%s", inTimezone);
|
sprintf(winStr, "TZ=%s", buf);
|
||||||
putenv(winStr);
|
putenv(winStr);
|
||||||
tzset();
|
tzset();
|
||||||
* get CURRENT time zone.
|
* get CURRENT time zone.
|
||||||
|
@ -70,44 +80,48 @@ void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *ou
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
||||||
|
*tsTimezone = tz;
|
||||||
tz += daylight;
|
tz += daylight;
|
||||||
/*
|
/*
|
||||||
* format:
|
* format:
|
||||||
* (CST, +0800)
|
* (CST, +0800)
|
||||||
* (BST, +0100)
|
* (BST, +0100)
|
||||||
*/
|
*/
|
||||||
sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||||
*outDaylight = daylight;
|
*outDaylight = daylight;
|
||||||
|
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
|
||||||
setenv("TZ", inTimezone, 1);
|
setenv("TZ", buf, 1);
|
||||||
tzset();
|
tzset();
|
||||||
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
||||||
|
*tsTimezone = tz;
|
||||||
tz += daylight;
|
tz += daylight;
|
||||||
|
|
||||||
sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||||
*outDaylight = daylight;
|
*outDaylight = daylight;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
setenv("TZ", inTimezone, 1);
|
setenv("TZ", buf, 1);
|
||||||
tzset();
|
tzset();
|
||||||
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
int32_t tz = (int32_t)((-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR);
|
||||||
|
*tsTimezone = tz;
|
||||||
tz += daylight;
|
tz += daylight;
|
||||||
sprintf(outTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
sprintf(outTimezoneStr, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||||
*outDaylight = daylight;
|
*outDaylight = daylight;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
taosMemoryFree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosGetSystemTimezone(char *outTimezone) {
|
void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
char *tz = getenv("TZ");
|
char *tz = getenv("TZ");
|
||||||
if (tz == NULL || strlen(tz) == 0) {
|
if (tz == NULL || strlen(tz) == 0) {
|
||||||
strcpy(outTimezone, "not configured");
|
strcpy(outTimezoneStr, "not configured");
|
||||||
} else {
|
} else {
|
||||||
strcpy(outTimezone, tz);
|
strcpy(outTimezoneStr, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(_TD_DARWIN_64)
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
@ -153,7 +167,7 @@ void taosGetSystemTimezone(char *outTimezone) {
|
||||||
* Asia/Shanghai (CST, +0800)
|
* Asia/Shanghai (CST, +0800)
|
||||||
* Europe/London (BST, +0100)
|
* Europe/London (BST, +0100)
|
||||||
*/
|
*/
|
||||||
snprintf(outTimezone, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
|
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
|
||||||
-timezone / 3600);
|
-timezone / 3600);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -168,13 +182,14 @@ void taosGetSystemTimezone(char *outTimezone) {
|
||||||
|
|
||||||
/* load time zone string from /etc/timezone */
|
/* load time zone string from /etc/timezone */
|
||||||
// FILE *f = fopen("/etc/timezone", "r");
|
// FILE *f = fopen("/etc/timezone", "r");
|
||||||
|
errno = 0;
|
||||||
TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ);
|
||||||
char buf[68] = {0};
|
char buf[68] = {0};
|
||||||
if (pFile != NULL) {
|
if (pFile != NULL) {
|
||||||
int len = taosReadFile(pFile, buf, 64);
|
int len = taosReadFile(pFile, buf, 64);
|
||||||
if (len < 64 && taosGetErrorFile(pFile)) {
|
if (len < 64 && taosGetErrorFile(pFile)) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
// printf("read /etc/timezone error, reason:%s", strerror(errno));
|
printf("read /etc/timezone error, reason:%s", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +217,7 @@ void taosGetSystemTimezone(char *outTimezone) {
|
||||||
* otherwise is GMT+00:00
|
* otherwise is GMT+00:00
|
||||||
*/
|
*/
|
||||||
int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR;
|
int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR;
|
||||||
|
*tsTimezone = tz;
|
||||||
tz += daylight;
|
tz += daylight;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -210,7 +226,7 @@ void taosGetSystemTimezone(char *outTimezone) {
|
||||||
* Asia/Shanghai (CST, +0800)
|
* Asia/Shanghai (CST, +0800)
|
||||||
* Europe/London (BST, +0100)
|
* Europe/London (BST, +0100)
|
||||||
*/
|
*/
|
||||||
snprintf(outTimezone, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue