Updated Examples and Recipes (markdown)

Howard Hinnant
2020-04-26 14:21:17 -04:00
parent 540cbc0008
commit 41394ea406

@@ -1733,7 +1733,7 @@ FILETIME system_clock_to_FILETIME(system_clock::time_point systemPoint) {
```c++ ```c++
#include "boost/date_time/posix_time/posix_time.hpp" #include "boost/date_time/posix_time/posix_time.hpp"
#include "date/date.h" #include <chrono>
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)
@@ -1752,23 +1752,15 @@ to_system_clock(boost::posix_time::ptime const& pt)
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 date;
using namespace std::chrono; using namespace std::chrono;
auto sd = floor<days>(st); using namespace boost;
year_month_day ymd = sd;
hh_mm_ss<system_clock::duration> hms{st - sd};
auto y = int(ymd.year());
auto m = unsigned(ymd.month());
auto d = unsigned(ymd.day());
auto h = hms.hours().count();
auto M = hms.minutes().count();
auto s = hms.seconds().count();
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
auto fs = nanoseconds(hms.subseconds()).count(); posix_time::nanoseconds fs{nanoseconds{st.time_since_epoch()}.count()};
#else #else
auto fs = duration_cast<microseconds>(hms.subseconds()).count(); posix_time::microseconds fs{duration_cast<microseconds>(
st.time_since_epoch()).count()};
#endif #endif
return {{y, m, d}, {h, M, s, fs}}; return posix_time::from_time_t(0) + fs;
} }
``` ```