27 lines
753 B
C++
27 lines
753 B
C++
#include "TimeSpan.h"
|
|
#include <boost/date_time/posix_time/time_formatters.hpp>
|
|
#include <boost/date_time/posix_time/time_parsers.hpp>
|
|
|
|
namespace bts::core {
|
|
|
|
TimeSpan TimeSpan::from_iso_string(const std::string &iso_string) {
|
|
const auto pdur = boost::posix_time::duration_from_string(iso_string);
|
|
return from_posix_duration(pdur);
|
|
}
|
|
|
|
std::string TimeSpan::to_iso_string() const {
|
|
const auto pdur = to_posix_duration();
|
|
return boost::posix_time::to_iso_string(pdur);
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &out, const TimeSpan &ts) noexcept {
|
|
out << ts.to_iso_string();
|
|
return out;
|
|
}
|
|
|
|
TimeSpan TimeSpan::from_posix_duration(boost::posix_time::time_duration d) {
|
|
return TimeSpan{d.total_nanoseconds()};
|
|
}
|
|
|
|
} // namespace bts::core
|