Add ParseServerTime TZ fix and tests

This commit is contained in:
John Marrett
2022-12-29 07:53:39 -05:00
parent 4ffbc39e3e
commit 2a6a1d70ff
2 changed files with 36 additions and 0 deletions
+15
View File
@@ -587,7 +587,22 @@ timeval CUtils::ParseServerTime(const CString& sTime) {
struct timeval tv;
memset(&tv, 0, sizeof(tv));
if (cp) {
char* oldTZ = getenv("TZ");
if (oldTZ) oldTZ = strdup(oldTZ);
setenv("TZ", "UTC", 1);
tzset();
tv.tv_sec = mktime(&stm);
// restore old value
if (oldTZ) {
setenv("TZ", oldTZ, 1);
free(oldTZ);
} else {
unsetenv("TZ");
}
tzset();
CString s_usec(cp);
if (s_usec.TrimPrefix(".") && s_usec.TrimSuffix("Z")) {
tv.tv_usec = s_usec.ToULong() * 1000;