fix(db): replace locatime with locatime_r for thread safe concern

Former-commit-id: 1b857e297c3b26e2730f86c67e8dc798755493fe
pull/191/head
Xu Peng 2019-05-27 10:35:41 +08:00
parent 37fc30e439
commit d744ef4a33
1 changed files with 9 additions and 7 deletions

View File

@ -4,6 +4,7 @@
* Proprietary and confidential.
******************************************************************************/
#include <ctime>
#include <stdio.h>
#include "Meta.h"
namespace zilliz {
@ -12,23 +13,24 @@ namespace engine {
namespace meta {
DateT Meta::GetDate(const std::time_t& t, int day_delta) {
tm *ltm = std::localtime(&t);
struct tm ltm;
localtime_r(&t, &ltm);
if (day_delta > 0) {
do {
++ltm->tm_mday;
++ltm.tm_mday;
--day_delta;
} while(day_delta > 0);
mktime(ltm);
mktime(&ltm);
} else if (day_delta < 0) {
do {
--ltm->tm_mday;
--ltm.tm_mday;
++day_delta;
} while(day_delta < 0);
mktime(ltm);
mktime(&ltm);
} else {
ltm->tm_mday;
ltm.tm_mday;
}
return ltm->tm_year*10000 + ltm->tm_mon*100 + ltm->tm_mday;
return ltm.tm_year*10000 + ltm.tm_mon*100 + ltm.tm_mday;
}
DateT Meta::GetDateWithDelta(int day_delta) {