mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-13 10:42:56 +01:00
commit
ba81287ca5
@ -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) ;
|
||||
}
|
||||
|
||||
|
||||
|
19
src/time.cpp
19
src/time.cpp
@ -78,10 +78,10 @@ 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);
|
||||
struct timespec systemtime_now() {
|
||||
struct timespec ts;
|
||||
timespec_get(&ts);
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
@ -155,8 +155,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 +172,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
|
||||
|
Loading…
Reference in New Issue
Block a user