feat:[TD-32642] add timezone support in windows
This commit is contained in:
parent
f23633e83d
commit
931a40985c
|
@ -665,16 +665,23 @@ MESSAGE(STATUS "timezone file path: " ${TZ_OUTPUT_PATH})
|
||||||
|
|
||||||
if(NOT ${TD_WINDOWS})
|
if(NOT ${TD_WINDOWS})
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND make CFLAGS+=-fPIC TZDIR=${TZ_OUTPUT_PATH}/ clean libtz.a
|
COMMAND make TZDIR=${TZ_OUTPUT_PATH}/ tzdir.h
|
||||||
WORKING_DIRECTORY "${TD_CONTRIB_DIR}/tz"
|
WORKING_DIRECTORY "${TD_CONTRIB_DIR}/tz"
|
||||||
)
|
)
|
||||||
|
|
||||||
# set(TZ_SRC_DIR "${TD_SOURCE_DIR}/source/os/src/timezone")
|
set(TZ_SRC_DIR "${TD_SOURCE_DIR}/source/os/src/timezone")
|
||||||
# file(MAKE_DIRECTORY ${TZ_SRC_DIR})
|
file(MAKE_DIRECTORY ${TZ_SRC_DIR})
|
||||||
# file(COPY ${TD_CONTRIB_DIR}/tz/private.h ${TD_CONTRIB_DIR}/tz/tzdir.h ${TD_CONTRIB_DIR}/tz/tzfile.h
|
file(COPY ${TD_CONTRIB_DIR}/tz/private.h ${TD_CONTRIB_DIR}/tz/tzdir.h ${TD_CONTRIB_DIR}/tz/tzfile.h
|
||||||
# ${TD_CONTRIB_DIR}/tz/localtime.c ${TD_CONTRIB_DIR}/tz/strftime.c
|
${TD_CONTRIB_DIR}/tz/localtime.c ${TD_CONTRIB_DIR}/tz/strftime.c
|
||||||
# DESTINATION ${TZ_SRC_DIR})
|
DESTINATION ${TZ_SRC_DIR})
|
||||||
endif(NOT ${TD_WINDOWS})
|
endif(NOT ${TD_WINDOWS})
|
||||||
|
|
||||||
|
#if(NOT ${TD_WINDOWS})
|
||||||
|
# execute_process(
|
||||||
|
# COMMAND make CFLAGS+=-fPIC CFLAGS+=-g TZDIR=${TZ_OUTPUT_PATH} clean libtz.a
|
||||||
|
# WORKING_DIRECTORY "${TD_CONTRIB_DIR}/tz"
|
||||||
|
# )
|
||||||
|
#endif(NOT ${TD_WINDOWS})
|
||||||
# ================================================================================================
|
# ================================================================================================
|
||||||
# Build test
|
# Build test
|
||||||
# ================================================================================================
|
# ================================================================================================
|
||||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
||||||
// When you want to use this feature, you should find or add the same function in the following section.
|
// When you want to use this feature, you should find or add the same function in the following section.
|
||||||
#ifndef ALLOW_FORBID_FUNC
|
#ifndef ALLOW_FORBID_FUNC
|
||||||
#define strptime STRPTIME_FUNC_TAOS_FORBID
|
#define strptime STRPTIME_FUNC_TAOS_FORBID
|
||||||
|
#define strftime STRFTIME_FUNC_TAOS_FORBID
|
||||||
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
|
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
|
||||||
#define localtime LOCALTIME_FUNC_TAOS_FORBID
|
#define localtime LOCALTIME_FUNC_TAOS_FORBID
|
||||||
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
|
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
|
||||||
|
@ -92,6 +93,7 @@ static FORCE_INLINE int64_t taosGetMonoTimestampMs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
|
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
|
||||||
|
size_t taosStrfTime(char *s, size_t maxsize, char const *format, struct tm const *t);
|
||||||
struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int32_t bufSize, timezone_t tz);
|
struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int32_t bufSize, timezone_t tz);
|
||||||
struct tm *taosGmTimeR(const time_t *timep, struct tm *result);
|
struct tm *taosGmTimeR(const time_t *timep, struct tm *result);
|
||||||
time_t taosTimeGm(struct tm *tmp);
|
time_t taosTimeGm(struct tm *tmp);
|
||||||
|
|
|
@ -2499,7 +2499,7 @@ static int32_t formatTimestamp(char* buf, size_t cap, int64_t val, int precision
|
||||||
TSDB_CHECK_CODE(code, lino, _end);
|
TSDB_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pos = strftime(buf, cap, "%Y-%m-%d %H:%M:%S", &ptm);
|
size_t pos = taosStrfTime(buf, cap, "%Y-%m-%d %H:%M:%S", &ptm);
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
TSDB_CHECK_CODE(code, lino, _end);
|
TSDB_CHECK_CODE(code, lino, _end);
|
||||||
|
|
|
@ -923,9 +923,9 @@ int32_t taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precisio
|
||||||
if (NULL == taosLocalTime(", &ptm, buf, bufLen, NULL)) {
|
if (NULL == taosLocalTime(", &ptm, buf, bufLen, NULL)) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||||
}
|
}
|
||||||
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm);
|
int32_t length = (int32_t)taosStrfTime(ts, 40, "%Y-%m-%dT%H:%M:%S", &ptm);
|
||||||
length += tsnprintf(ts + length, fractionLen, format, mod);
|
length += tsnprintf(ts + length, fractionLen, format, mod);
|
||||||
length += (int32_t)strftime(ts + length, 40 - length, "%z", &ptm);
|
length += (int32_t)taosStrfTime(ts + length, 40 - length, "%z", &ptm);
|
||||||
|
|
||||||
tstrncpy(buf, ts, bufLen);
|
tstrncpy(buf, ts, bufLen);
|
||||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
|
|
|
@ -195,7 +195,7 @@ static int32_t addTimezoneParam(SNodeList* pList, timezone_t tz) {
|
||||||
}
|
}
|
||||||
struct tm tmInfo;
|
struct tm tmInfo;
|
||||||
if (taosLocalTime(&t, &tmInfo, buf, sizeof(buf), tz) != NULL) {
|
if (taosLocalTime(&t, &tmInfo, buf, sizeof(buf), tz) != NULL) {
|
||||||
(void)strftime(buf, sizeof(buf), "%z", &tmInfo);
|
(void)taosStrfTime(buf, sizeof(buf), "%z", &tmInfo);
|
||||||
}
|
}
|
||||||
int32_t len = (int32_t)strlen(buf);
|
int32_t len = (int32_t)strlen(buf);
|
||||||
|
|
||||||
|
|
|
@ -2249,7 +2249,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = (int32_t)strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo);
|
int32_t len = (int32_t)taosStrfTime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo);
|
||||||
|
|
||||||
len += tsnprintf(buf + len, fractionLen, format, mod);
|
len += tsnprintf(buf + len, fractionLen, format, mod);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
aux_source_directory(src OS_SRC)
|
aux_source_directory(src OS_SRC)
|
||||||
|
if(NOT ${TD_WINDOWS})
|
||||||
|
aux_source_directory(src/timezone OS_TZ)
|
||||||
|
add_library(os STATIC ${OS_SRC} ${OS_TZ})
|
||||||
|
else()
|
||||||
add_library(os STATIC ${OS_SRC})
|
add_library(os STATIC ${OS_SRC})
|
||||||
|
endif(NOT ${TD_WINDOWS})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
os
|
os
|
||||||
PUBLIC "${TD_SOURCE_DIR}/include/os"
|
PUBLIC "${TD_SOURCE_DIR}/include/os"
|
||||||
|
@ -70,10 +75,10 @@ IF (JEMALLOC_ENABLED)
|
||||||
target_link_libraries(os PUBLIC -L${CMAKE_BINARY_DIR}/build/lib -ljemalloc)
|
target_link_libraries(os PUBLIC -L${CMAKE_BINARY_DIR}/build/lib -ljemalloc)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
if(NOT ${TD_WINDOWS})
|
#if(NOT ${TD_WINDOWS})
|
||||||
find_library(tz libtz.a "${TD_SOURCE_DIR}/contrib/tz")
|
# find_library(tz libtz.a "${TD_SOURCE_DIR}/contrib/tz")
|
||||||
target_link_libraries(os PUBLIC ${tz})
|
# target_link_libraries(os PUBLIC ${tz})
|
||||||
endif(NOT ${TD_WINDOWS})
|
#endif(NOT ${TD_WINDOWS})
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
|
@ -345,6 +345,12 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
taosStrfTime(char *s, size_t maxsize, char const *format, struct tm const *t){
|
||||||
|
if (!s || !format || !t) return 0;
|
||||||
|
return strftime(s, maxsize, format, t);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t taosGetTimeOfDay(struct timeval *tv) {
|
int32_t taosGetTimeOfDay(struct timeval *tv) {
|
||||||
if (tv == NULL) {
|
if (tv == NULL) {
|
||||||
return TSDB_CODE_INVALID_PARA;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
|
|
@ -813,13 +813,13 @@ int32_t taosFormatTimezoneStr(time_t t, const char* tz, timezone_t sp, char *out
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char str1[TD_TIMEZONE_LEN] = {0};
|
char str1[TD_TIMEZONE_LEN] = {0};
|
||||||
if (strftime(str1, sizeof(str1), "%Z", &tm1) == 0){
|
if (taosStrfTime(str1, sizeof(str1), "%Z", &tm1) == 0){
|
||||||
uError("failed to get timezone name");
|
uError("failed to get timezone name");
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
char str2[TD_TIMEZONE_LEN] = {0};
|
char str2[TD_TIMEZONE_LEN] = {0};
|
||||||
if (strftime(str2, sizeof(str2), "%z", &tm1) == 0){
|
if (taosStrfTime(str2, sizeof(str2), "%z", &tm1) == 0){
|
||||||
uError("failed to get timezone offset");
|
uError("failed to get timezone offset");
|
||||||
return TSDB_CODE_TIME_ERROR;
|
return TSDB_CODE_TIME_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ static int32_t getDay(char *buf, int32_t bufSize) {
|
||||||
}
|
}
|
||||||
struct tm tmInfo;
|
struct tm tmInfo;
|
||||||
if (taosLocalTime(&t, &tmInfo, buf, bufSize, NULL) != NULL) {
|
if (taosLocalTime(&t, &tmInfo, buf, bufSize, NULL) != NULL) {
|
||||||
TAOS_UNUSED(strftime(buf, bufSize, "%Y-%m-%d", &tmInfo));
|
TAOS_UNUSED(taosStrfTime(buf, bufSize, "%Y-%m-%d", &tmInfo));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -475,7 +475,7 @@ static char* shellFormatTimestamp(char* buf, int32_t bufSize, int64_t val, int32
|
||||||
if (taosLocalTime(&tt, &ptm, buf, bufSize, NULL) == NULL) {
|
if (taosLocalTime(&tt, &ptm, buf, bufSize, NULL) == NULL) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
size_t pos = taosStrfTime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
|
||||||
|
|
||||||
if (precision == TSDB_TIME_PRECISION_NANO) {
|
if (precision == TSDB_TIME_PRECISION_NANO) {
|
||||||
sprintf(buf + pos, ".%09d", ms);
|
sprintf(buf + pos, ".%09d", ms);
|
||||||
|
|
|
@ -800,7 +800,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
|
||||||
if (taosLocalTime(&tt, &tp, timeStr, sizeof(timeStr), NULL) == NULL) {
|
if (taosLocalTime(&tt, &tp, timeStr, sizeof(timeStr), NULL) == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", &tp);
|
taosStrfTime(timeStr, 64, "%y-%m-%d %H:%M:%S", &tp);
|
||||||
if (precision == TSDB_TIME_PRECISION_MILLI) {
|
if (precision == TSDB_TIME_PRECISION_MILLI) {
|
||||||
sprintf(value, "%s.%03d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000));
|
sprintf(value, "%s.%03d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000));
|
||||||
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
|
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
|
||||||
|
|
Loading…
Reference in New Issue