Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,18 @@ std::string string_strip(const std::string & str) {
std::string string_get_sortable_timestamp() {
using clock = std::chrono::system_clock;

const clock::time_point current_time = clock::now();
const time_t as_time_t = clock::to_time_t(current_time);
const auto current_time = clock::now();
const auto as_time_t = std::chrono::duration_cast<std::chrono::seconds>(current_time.time_since_epoch()).count();

struct tm timeinfo;
#ifdef _WIN32
gmtime_s(&timeinfo, &as_time_t);
#else
gmtime_r(&as_time_t, &timeinfo);
#endif

char timestamp_no_ns[100];
std::strftime(timestamp_no_ns, 100, "%Y_%m_%d-%H_%M_%S", std::localtime(&as_time_t));
std::strftime(timestamp_no_ns, 100, "%Y_%m_%d-%H_%M_%S", &timeinfo);

const int64_t ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
current_time.time_since_epoch() % 1000000000).count();
Expand Down
Loading