fix: ostime

This commit is contained in:
xsren 2024-09-29 15:29:09 +08:00
parent 2f3fe7ba42
commit 6d0d2ae039
1 changed files with 20 additions and 2 deletions

View File

@ -742,6 +742,20 @@ char *tz_win[554][2] = {{"Asia/Shanghai", "China Standard Time"},
static int isdst_now = 0;
void parseTimeStr(char *p, char to[5]) {
for (int i = 0; i < 5; ++i) {
if (strlen(p) > i) {
to[i] = p[i];
} else {
to[i] = '0';
}
}
if (strlen(p) == 2) {
to[1] = '0';
to[2] = p[1];
}
}
int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight,
enum TdTimezone *tsTimezone) {
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) {
@ -798,7 +812,9 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
memcpy(&winStr[3], pp, ppp - pp);
indexStr = ppp - pp + 3;
}
sprintf(&winStr[indexStr], "%c%c%c:%c%c:00", (p[0] == '+' ? '+' : '-'), p[1], p[2], p[3], p[4]);
char to[5];
parseTimeStr(p, to);
sprintf(&winStr[indexStr], "%c%c%c:%c%c:00", (to[0] == '+' ? '+' : '-'), to[1], to[2], to[3], to[4]);
*tsTimezone = -taosStr2Int32(p, NULL, 10);
} else {
*tsTimezone = 0;
@ -806,7 +822,9 @@ int32_t taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, i
}
_putenv(winStr);
_tzset();
if (outTimezoneStr != inTimezoneStr) {
strcpy(outTimezoneStr, inTimezoneStr);
}
*outDaylight = 0;
#elif defined(_TD_DARWIN_64)