From 26f76cd103c532f3a56e555a98f2429060aa755c Mon Sep 17 00:00:00 2001 From: Kjell Hedstrom Date: Thu, 25 Aug 2016 00:49:17 -0600 Subject: [PATCH 1/2] bugfix time formatting --- src/g3log/time.hpp | 6 +++--- src/time.cpp | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/g3log/time.hpp b/src/g3log/time.hpp index 89bd7e2..6227972 100644 --- a/src/g3log/time.hpp +++ b/src/g3log/time.hpp @@ -40,8 +40,9 @@ namespace g3 { - // wrap for std::chrono::system_clock::now() - std::time_t systemtime_now(); + // custom wrap for std::chrono::system_clock::now()but this one + // returns timespec struct instead which is what we use in g3log + struct timespec systemtime_now(); // OSX, Windows needed wrapper for std::timespec_get(struct timespec *ts, int base) // OSX and Windows also lacks the POSIX clock_gettime(int base, struct timespec *ts) @@ -63,7 +64,6 @@ namespace g3 { * std::put_time. A possible fix if your c++11 library is not updated is to * modify this to use std::strftime instead */ std::string localtime_formatted(const timespec& time_snapshot, const std::string& time_format) ; - std::string localtime_formatted(const std::time_t& time_snapshot, const std::string& time_format) ; } diff --git a/src/time.cpp b/src/time.cpp index 073526f..fa5eac5 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -79,9 +79,15 @@ namespace g3 { namespace g3 { - std::time_t systemtime_now() { - system_time_point system_now = std::chrono::system_clock::now(); - return std::chrono::system_clock::to_time_t(system_now); + // timespec_get systemtime_now() { + // system_time_point system_now = std::chrono::system_clock::now(); + // return std::chrono::system_clock::to_time_t(system_now); + // } + + struct timespec systemtime_now() { + struct timespec ts; + timespec_get(&ts); + return ts; } @@ -155,8 +161,6 @@ namespace g3 { - - std::string localtime_formatted(const timespec& time_snapshot, const std::string& time_format) { auto format_buffer = time_format; // copying format string to a separate buffer @@ -174,12 +178,7 @@ namespace g3 { // replacing "%f[3|6|9]" with sec fractional part value format_buffer.replace(pos, g3::internal::kFractionalIdentier.size() + padding, value); } - - return localtime_formatted(time_snapshot.tv_sec, format_buffer); - } - - std::string localtime_formatted(const std::time_t& time_snapshot, const std::string& time_format) { - std::tm t = localtime(time_snapshot); // could be const, but cannot due to VS2012 is non conformant for C++11's std::put_time (see above) - return g3::put_time(&t, time_format.c_str()); // format example: //"%Y/%m/%d %H:%M:%S"); + std::tm t = localtime(time_snapshot.tv_sec); + return g3::put_time(&t, format_buffer.c_str()); // format example: //"%Y/%m/%d %H:%M:%S"); } } // g3 From e0fb4fd24ee4a192f584f2a13101406a5be04efb Mon Sep 17 00:00:00 2001 From: Kjell Hedstrom Date: Thu, 25 Aug 2016 00:51:21 -0600 Subject: [PATCH 2/2] fixit --- src/time.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/time.cpp b/src/time.cpp index fa5eac5..47fe8bd 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -78,12 +78,6 @@ namespace g3 { namespace g3 { - - // timespec_get systemtime_now() { - // system_time_point system_now = std::chrono::system_clock::now(); - // return std::chrono::system_clock::to_time_t(system_now); - // } - struct timespec systemtime_now() { struct timespec ts; timespec_get(&ts);