From 4c97427e0cf7e6cdc86f358428de2f42c6dc1b27 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 00:15:13 +0800 Subject: [PATCH] [td-225] fix bugs in parse time --- src/common/src/ttimezone.c | 1 + src/util/src/ttime.c | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c index ae6ffea59a..ed62357c4d 100644 --- a/src/common/src/ttimezone.c +++ b/src/common/src/ttimezone.c @@ -20,6 +20,7 @@ #include "tconfig.h" #include "tutil.h" +// TODO refactor to set the tz value through parameter void tsSetTimeZone() { SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); uPrint("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index dfec632012..176f9be7fb 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -48,23 +48,21 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, const unsigned int day, const unsigned int hour, const unsigned int min, const unsigned int sec) { - unsigned int mon = mon0, year = year0; - - /* 1..12 -> 11,12,1..10 */ - if (0 >= (int) (mon -= 2)) { - mon += 12; /* Puts Feb last since it has leap day */ - year -= 1; - } - - //int64_t res = (((((int64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) + - // year*365 - 719499)*24 + hour)*60 + min)*60 + sec); - int64_t res; - res = 367*((int64_t)mon)/12; - res += year/4 - year/100 + year/400 + day + year*365 - 719499; + unsigned int mon = mon0, year = year0; + + /* 1..12 -> 11,12,1..10 */ + if (0 >= (int) (mon -= 2)) { + mon += 12; /* Puts Feb last since it has leap day */ + year -= 1; + } + + int64_t res = 367*((int64_t)mon)/12; + + res += ((int64_t)(year/4 - year/100 + year/400 + day + year*365) - 719499); // this value may be less than 0 res = res*24; res = ((res + hour) * 60 + min) * 60 + sec; - return (res + timezone); + return (res + timezone); } // ==== mktime() kernel code =================// static int64_t m_deltaUtc = 0; -- GitLab