From ff4852e301befd37e9937f250809a45e08eeff2e Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 7 Jul 2017 21:31:42 -0400 Subject: [PATCH] Updated Boost datetime Examples Translated (markdown) --- Boost-datetime-Examples-Translated.md | 64 +++++++++++++-------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Boost-datetime-Examples-Translated.md b/Boost-datetime-Examples-Translated.md index 502ac84..5035988 100644 --- a/Boost-datetime-Examples-Translated.md +++ b/Boost-datetime-Examples-Translated.md @@ -480,44 +480,44 @@ main() ``` ### Flight Time Example +```c++ +#include "tz.h" +#include - #include "tz.h" - #include +int +main() +{ + using namespace std::chrono; + using namespace date; - int - main() - { - using namespace std::chrono; - using namespace date; + // set up some timezones for creating and adjusting local times + auto phx_tz = locate_zone("America/Phoenix"); + auto nyc_tz = locate_zone("America/New_York"); - // set up some timezones for creating and adjusting local times - auto phx_tz = locate_zone("America/Phoenix"); - auto nyc_tz = locate_zone("America/New_York"); + // local departure time in phoenix is 11 pm on March 30 2005 + // (ny changes to dst on apr 3 at 2 am) + auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h); - // local departure time in phoenix is 11 pm on March 30 2005 - // (ny changes to dst on apr 3 at 2 am) - auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h); + // flight is 4 hours, 30 minutes + auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min); + auto nyc_arrival = make_zoned(nyc_tz, phx_arrival); - // flight is 4 hours, 30 minutes - auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min); - auto nyc_arrival = make_zoned(nyc_tz, phx_arrival); - - std::cout << "departure phx time: " << phx_departure << '\n'; - std::cout << "arrival phx time: " << phx_arrival << '\n'; - std::cout << "arrival nyc time: " << nyc_arrival << '\n'; - } - - // Output: - // - // departure phx time: 2005-03-30 23:00 - // arrival phx time: 2005-03-31 03:30 MST - // arrival nyc time: 2005-03-31 05:30 EST - // - // Note that boost states a nyc_arrival time of 2005-Mar-31 06:30:00 EDT - // because boost uses the current US daylightsavings rules as opposed to - // those that were in effect in 2005. This library varies its DST rules - // with the date. + std::cout << "departure phx time: " << phx_departure << '\n'; + std::cout << "arrival phx time: " << phx_arrival << '\n'; + std::cout << "arrival nyc time: " << nyc_arrival << '\n'; +} +// Output: +// +// departure phx time: 2005-03-30 23:00 +// arrival phx time: 2005-03-31 03:30 MST +// arrival nyc time: 2005-03-31 05:30 EST +// +// Note that boost states a nyc_arrival time of 2005-Mar-31 06:30:00 EDT +// because boost uses the current US daylightsavings rules as opposed to +// those that were in effect in 2005. This library varies its DST rules +// with the date. +``` ### Seconds Since Epoch