feat(Core/Time): remove inherited ACE Time (#3455)

Co-authored-by: Viste <viste02@gmail.com>
This commit is contained in:
Kargatum
2020-09-11 19:03:26 +07:00
committed by GitHub
parent 8b3621779e
commit e15a493927
20 changed files with 157 additions and 58 deletions

View File

@@ -102,6 +102,45 @@ Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserv
}
}
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
struct tm* localtime_r(time_t const* time, struct tm* result)
{
localtime_s(result, time);
return result;
}
#endif
tm TimeBreakdown(time_t time)
{
tm timeLocal;
localtime_r(&time, &timeLocal);
return timeLocal;
}
time_t LocalTimeToUTCTime(time_t time)
{
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
return time + _timezone;
#else
return time + timezone;
#endif
}
time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
{
tm timeLocal = TimeBreakdown(time);
timeLocal.tm_hour = 0;
timeLocal.tm_min = 0;
timeLocal.tm_sec = 0;
time_t midnightLocal = mktime(&timeLocal);
time_t hourLocal = midnightLocal + hour * HOUR;
if (onlyAfterTime && hourLocal <= time)
hourLocal += DAY;
return hourLocal;
}
void stripLineInvisibleChars(std::string &str)
{
static std::string const invChars = " \t\7\n";
@@ -227,7 +266,7 @@ uint32 TimeStringToSecs(const std::string& timestring)
std::string TimeToTimestampStr(time_t t)
{
tm aTm;
ACE_OS::localtime_r(&t, &aTm);
localtime_r(&t, &aTm);
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
@@ -245,6 +284,15 @@ std::string TimeToTimestampStr(time_t t)
return std::string(buf);
}
std::string TimeToHumanReadable(time_t t)
{
tm time;
localtime_r(&t, &time);
char buf[30];
strftime(buf, 30, "%c", &time);
return std::string(buf);
}
/// Check if the string is a valid ip address representation
bool IsIPAddress(char const* ipaddress)
{