eis/eqpm/utility.cc

33 lines
984 B
C++

#include <eqpm/utility.h>
namespace UtilityTools {
TimePoint time_point2zero(TimePoint time_point) {
return second_zero2time_point(time_point2second_zero(time_point));
}
int time_point2second_zero(TimePoint time_point) {
int seconds = (time_point.time_since_epoch().count()) / (size_t)pow(10, 9);
return 86400 * (int)((seconds + 28800) / 86400) - 28800;
}
TimePoint second_zero2time_point(int seconds) {
auto st_s = std::chrono::seconds(seconds);
auto time_date =
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>(
st_s);
return time_date;
}
int diff_days(TimePoint stime, TimePoint etime) {
return std::chrono::duration_cast<days>(etime - stime).count();
}
TimePoint string2TimePoint(std::string time_str, const std::string& fmt) {
std::tm tm = {};
std::stringstream ss(time_str);
ss >> std::get_time(&tm, fmt.c_str());
return std::chrono::system_clock::from_time_t(std::mktime(&tm));
}
} // namespace UtilityTools