2015-11-19 20:17:35 +00:00
|
|
|
#include "tools.h"
|
2016-08-09 20:31:16 +00:00
|
|
|
#include "platformTools.h"
|
2016-03-01 20:57:05 +00:00
|
|
|
#include <format.h>
|
|
|
|
#include <chrono>
|
2016-04-13 20:37:39 +00:00
|
|
|
#include <vector>
|
2016-03-01 20:57:05 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::chrono::duration;
|
|
|
|
|
|
|
|
string formatDuration(duration<double> seconds) {
|
|
|
|
return fmt::format("{0:.2f}", seconds.count());
|
|
|
|
}
|
2016-04-13 20:37:39 +00:00
|
|
|
|
|
|
|
string formatTime(time_t time, const string& format) {
|
2016-08-09 20:31:16 +00:00
|
|
|
tm timeInfo = getLocalTime(time);
|
2016-04-13 20:37:39 +00:00
|
|
|
std::vector<char> buffer(20);
|
|
|
|
bool success = false;
|
|
|
|
while (!success) {
|
2016-06-26 09:06:44 +00:00
|
|
|
success = strftime(buffer.data(), buffer.size(), format.c_str(), &timeInfo) != 0;
|
2016-04-13 20:37:39 +00:00
|
|
|
if (!success) buffer.resize(buffer.size() * 2);
|
|
|
|
}
|
|
|
|
return string(buffer.data());
|
|
|
|
}
|