time on linx fix

v1
Brett 2024-02-22 15:52:01 -05:00
parent 89bde7c6e8
commit e9a11a9a7e
2 changed files with 16 additions and 8 deletions

View File

@ -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); \

View File

@ -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);