rhubarb-lip-sync/src/tools.cpp

24 lines
572 B
C++
Raw Normal View History

#include "tools.h"
2016-03-01 20:57:05 +00:00
#include <format.h>
#include <chrono>
#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());
}
string formatTime(time_t time, const string& format) {
2016-06-26 09:06:44 +00:00
tm timeInfo;
localtime_s(&timeInfo, &time);
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;
if (!success) buffer.resize(buffer.size() * 2);
}
return string(buffer.data());
}