diff --git a/include/blt/std/logging.h b/include/blt/std/logging.h index de24877..a4b3728 100644 --- a/include/blt/std/logging.h +++ b/include/blt/std/logging.h @@ -318,8 +318,14 @@ namespace blt::logging { delete(output); } }; - -#define BLT_NOW() auto t = std::time(nullptr); tm now; localtime_s(&now, &t); //auto now = std::localtime(&t) + +#ifdef WIN32 + #define BLT_NOW() auto t = std::time(nullptr); tm now{}; localtime_s(&now, &t) +#else + #define BLT_NOW() auto t = std::time(nullptr); auto now_ptr = std::localtime(&t); auto& now = *now_ptr +#endif + +//#define BLT_NOW() auto t = std::time(nullptr); tm now; localtime_s(&now, &t); //auto now = std::localtime(&t) #define BLT_ISO_YEAR(S) auto S = std::to_string(now.tm_year + 1900); \ S += '-'; \ S += ensureHasDigits(now.tm_mon+1, 2); \ diff --git a/include/blt/std/time.h b/include/blt/std/time.h index ade6954..247bedb 100644 --- a/include/blt/std/time.h +++ b/include/blt/std/time.h @@ -13,6 +13,11 @@ namespace blt::system { +#ifdef WIN32 + #define TIME_FUNC tm now{}; localtime_s(&now, &t) +#else + #define TIME_FUNC auto now_ptr = std::localtime(&t); auto& now = *now_ptr +#endif static inline std::string ensureHasDigits(int current, int digits) { @@ -86,8 +91,7 @@ namespace blt::system static inline std::string getTimeString() { auto t = std::time(nullptr); - tm now{}; - localtime_s(&now, &t); + TIME_FUNC; //auto now = std::localtime(&t); std::stringstream timeString; timeString << (1900 + now.tm_year); @@ -112,8 +116,7 @@ namespace blt::system static inline std::string getTimeStringLog() { auto t = std::time(nullptr); - tm now{}; - localtime_s(&now, &t); + TIME_FUNC; //auto now = std::localtime(&t); std::string timeString = "["; timeString += ensureHasDigits(now.tm_hour, 2); @@ -131,8 +134,7 @@ namespace blt::system static inline std::string getTimeStringFS() { auto t = std::time(nullptr); - tm now{}; - localtime_s(&now, &t); + TIME_FUNC; //auto now = std::localtime(&t); std::stringstream timeString; timeString << (1900 + now.tm_year);