Updated Examples and Recipes (markdown)

Howard Hinnant
2020-04-26 15:12:09 -04:00
parent 41394ea406
commit 03d3bfb0c7

@@ -1738,27 +1738,31 @@ FILETIME system_clock_to_FILETIME(system_clock::time_point systemPoint) {
std::chrono::system_clock::time_point std::chrono::system_clock::time_point
to_system_clock(boost::posix_time::ptime const& pt) to_system_clock(boost::posix_time::ptime const& pt)
{ {
using namespace std::chrono; using namespace std;
auto const dt = pt - boost::posix_time::from_time_t(0); using namespace boost;
auto const dt = pt - posix_time::from_time_t(0);
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
std::chrono::nanoseconds ns{dt.total_nanoseconds()}; chrono::nanoseconds ns{dt.total_nanoseconds()};
return system_clock::time_point{duration_cast<system_clock::duration>(ns)}; auto sysd = chrono::duration_cast<chrono::system_clock::duration>(ns);
return chrono::system_clock::time_point{sysd};
#else #else
std::chrono::microseconds us{dt.total_microseconds()}; chrono::microseconds us{dt.total_microseconds()};
return system_clock::time_point{us}; return chrono::system_clock::time_point{us};
#endif #endif
} }
boost::posix_time::ptime boost::posix_time::ptime
to_ptime(std::chrono::system_clock::time_point const& st) to_ptime(std::chrono::system_clock::time_point const& st)
{ {
using namespace std::chrono; using namespace std;
using namespace boost; using namespace boost;
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
posix_time::nanoseconds fs{nanoseconds{st.time_since_epoch()}.count()}; posix_time::nanoseconds fs{
chrono::nanoseconds{st.time_since_epoch()}.count()};
#else #else
posix_time::microseconds fs{duration_cast<microseconds>( posix_time::microseconds fs{
st.time_since_epoch()).count()}; chrono::duration_cast<chrono::microseconds>(
st.time_since_epoch()).count()};
#endif #endif
return posix_time::from_time_t(0) + fs; return posix_time::from_time_t(0) + fs;
} }