diff --git a/Boost-datetime-Examples-Translated.md b/Boost-datetime-Examples-Translated.md index 3a9fba1..1a9fcc5 100644 --- a/Boost-datetime-Examples-Translated.md +++ b/Boost-datetime-Examples-Translated.md @@ -387,50 +387,49 @@ main() ``` ### Local to UTC Conversion +```c++ +#include "tz.h" +#include - #include "date.h" - #include "tz.h" - #include +int +main() +{ + using namespace std::chrono; + using namespace date; + auto zone = current_zone(); + auto t10 = sys_days(2002_y/jan/1) + 7h; + auto t11 = make_zoned(zone, t10); + std::cout << "UTC <--> Zone base on current setting\n"; + std::cout << t11 << " is " << t10 << " UTC time\n"; + auto td = t11.get_local_time().time_since_epoch() - t10.time_since_epoch(); + std::cout << "A difference of: " << format("%T\n", td); - int - main() - { - using namespace std::chrono; - using namespace date; - auto zone = current_zone(); - auto t10 = sys_days(2002_y/jan/1) + 7h; - auto t11 = make_zoned(zone, t10); - std::cout << "UTC <--> Zone base on current setting\n"; - std::cout << t11 << " is " << t10 << " UTC time\n"; - auto td = t11.get_local_time().time_since_epoch() - t10.time_since_epoch(); - std::cout << "A difference of: " << make_time(td) << '\n'; + // eastern timezone is utc-5 + zone = locate_zone("America/New_York"); + // 5 hours b/f midnight NY time + auto t1 = local_days{2001_y/dec/31} + 19h + 0s; + std::cout << "\nUTC <--> New York while DST is NOT active (5 hours)\n"; + auto t2 = make_zoned(zone, t1); + std::cout << t1 << " in New York is " << t2.get_sys_time() << " UTC time\n"; - // eastern timezone is utc-5 - zone = locate_zone("America/New_York"); - // 5 hours b/f midnight NY time - auto t1 = local_days{2001_y/dec/31} + 19h + 0s; - std::cout << "\nUTC <--> New York while DST is NOT active (5 hours)\n"; - auto t2 = make_zoned(zone, t1); - std::cout << t1 << " in New York is " << t2.get_sys_time() << " UTC time\n"; + std::cout << t2.get_sys_time() << " UTC is " << t2.get_local_time() << " New York time\n\n"; - std::cout << t2.get_sys_time() << " UTC is " << t2.get_local_time() << " New York time\n\n"; + // 4 hours b/f midnight NY time + auto t4 = local_days{2002_y/may/31} + 20h + 0s; + std::cout << "UTC <--> New York while DST is active (4 hours)\n"; + auto t5 = make_zoned(zone, t4); + std::cout << t4 << " in New York is " << t5.get_sys_time() << " UTC time\n"; - // 4 hours b/f midnight NY time - auto t4 = local_days{2002_y/may/31} + 20h + 0s; - std::cout << "UTC <--> New York while DST is active (4 hours)\n"; - auto t5 = make_zoned(zone, t4); - std::cout << t4 << " in New York is " << t5.get_sys_time() << " UTC time\n"; - - std::cout << t5.get_sys_time() << " UTC is " << t5.get_local_time() << " New York time\n\n"; - - // Arizona timezone is utc-7 with no dst - zone = locate_zone("America/Phoenix"); - auto t7 = local_days(2002_y/may/31) + 17h + 0s; - std::cout << "UTC <--> Arizona (7 hours)\n"; - auto t8 = zone->to_sys(t7); - std::cout << t7 << " in Arizona is " << t8 << " UTC time\n"; - } + std::cout << t5.get_sys_time() << " UTC is " << t5.get_local_time() << " New York time\n\n"; + // Arizona timezone is utc-7 with no dst + zone = locate_zone("America/Phoenix"); + auto t7 = local_days(2002_y/may/31) + 17h + 0s; + std::cout << "UTC <--> Arizona (7 hours)\n"; + auto t8 = zone->to_sys(t7); + std::cout << t7 << " in Arizona is " << t8 << " UTC time\n"; +} +``` ### Time Periods