From 41394ea4067b42e34985e4360309120ec5a643e6 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sun, 26 Apr 2020 14:21:17 -0400 Subject: [PATCH] Updated Examples and Recipes (markdown) --- Examples-and-Recipes.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Examples-and-Recipes.md b/Examples-and-Recipes.md index 6eda81d..c9a0fed 100644 --- a/Examples-and-Recipes.md +++ b/Examples-and-Recipes.md @@ -1733,7 +1733,7 @@ FILETIME system_clock_to_FILETIME(system_clock::time_point systemPoint) { ```c++ #include "boost/date_time/posix_time/posix_time.hpp" -#include "date/date.h" +#include std::chrono::system_clock::time_point 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 to_ptime(std::chrono::system_clock::time_point const& st) { - using namespace date; using namespace std::chrono; - auto sd = floor(st); - year_month_day ymd = sd; - hh_mm_ss 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(); + using namespace boost; #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS - auto fs = nanoseconds(hms.subseconds()).count(); + posix_time::nanoseconds fs{nanoseconds{st.time_since_epoch()}.count()}; #else - auto fs = duration_cast(hms.subseconds()).count(); + posix_time::microseconds fs{duration_cast( + st.time_since_epoch()).count()}; #endif - return {{y, m, d}, {h, M, s, fs}}; + return posix_time::from_time_t(0) + fs; } ```