44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
#include "mix_cc/ihyper_db/utility.h"
|
|
using std::string;
|
|
|
|
namespace mix_cc {
|
|
namespace ihd {
|
|
|
|
HD3TimeRegion convert_to_hd_tr(const time_range_t& my_range) {
|
|
HD3TimeRegion time_region;
|
|
if (my_range.get_left() > my_range.get_right()) {
|
|
throw std::runtime_error("start is bigger than end");
|
|
}
|
|
time_region.left = convert_to_hd_tp(my_range.get_left());
|
|
time_region.right = convert_to_hd_tp(my_range.get_right());
|
|
time_region.bLeftClosed = true;
|
|
time_region.bRightClosed = false;
|
|
return time_region;
|
|
}
|
|
|
|
time_range_t convert_to_tr(const HD3TimeRegion& time_region) {
|
|
return time_range_t{
|
|
system_clock::time_point(milliseconds(time_region.left.nMsec) +
|
|
seconds(time_region.left.nSec)),
|
|
system_clock::time_point(milliseconds(time_region.right.nMsec) +
|
|
seconds(time_region.right.nSec))};
|
|
}
|
|
|
|
std::chrono::system_clock::time_point convert_to_tp(uint64_t nSec,
|
|
unsigned int nMsec) {
|
|
return std::chrono::system_clock::time_point(
|
|
std::chrono::milliseconds(nMsec) + std::chrono::seconds(nSec));
|
|
}
|
|
|
|
HD3Time convert_to_hd_tp(std::chrono::system_clock::time_point time_point) {
|
|
HD3Time hd_tp;
|
|
hd_tp.nSec = duration_cast<seconds>(time_point.time_since_epoch()).count();
|
|
hd_tp.nMsec = duration_cast<milliseconds>(
|
|
(time_point - seconds(hd_tp.nSec)).time_since_epoch())
|
|
.count();
|
|
return hd_tp;
|
|
}
|
|
} // namespace ihd
|
|
|
|
} // namespace mix_cc
|