From 8c3531f259492d09161f754c62dbcdc370a41727 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 7 Jul 2017 18:16:04 -0400 Subject: [PATCH] Updated Boost datetime Examples Translated (markdown) --- Boost-datetime-Examples-Translated.md | 114 +++++++++++++------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/Boost-datetime-Examples-Translated.md b/Boost-datetime-Examples-Translated.md index b1f39e7..b978b89 100644 --- a/Boost-datetime-Examples-Translated.md +++ b/Boost-datetime-Examples-Translated.md @@ -153,72 +153,72 @@ main() ``` ### Localization Demonstration +```c++ +#include "date.h" +#include +#include - #include "date.h" - #include - #include +// Define a series of char arrays for short and long name strings +// to be associated with German date output (US names will be +// retrieved from the locale). +const char* const de_long_month_names[] = +{ + "Januar", "Februar", "Marz", "April", "Mai", + "Juni", "Juli", "August", "September", "Oktober", + "November", "Dezember", "NichtDerMonat" +}; - // Define a series of char arrays for short and long name strings - // to be associated with German date output (US names will be - // retrieved from the locale). - const char* const de_long_month_names[] = - { - "Januar", "Februar", "Marz", "April", "Mai", - "Juni", "Juli", "August", "September", "Oktober", - "November", "Dezember", "NichtDerMonat" - }; +const char* const de_long_weekday_names[] = +{ + "Sonntag", "Montag", "Dienstag", "Mittwoch", + "Donnerstag", "Freitag", "Samstag" +}; - const char* const de_long_weekday_names[] = - { - "Sonntag", "Montag", "Dienstag", "Mittwoch", - "Donnerstag", "Freitag", "Samstag" - }; +int +main() +{ + using namespace date; - int - main() - { - using namespace date; - - // create some gregorian objects to output - auto d1 = 2002_y/oct/1; - auto m = d1.month(); - auto wd = weekday{d1}; - - using namespace std; - // output the date in German using short month names - cout << d1.day() << '.' - << setw(2) << static_cast(d1.month()) - << '.' << d1.year() << '\n'; - cout << de_long_month_names[static_cast(m)-1] << '\n'; - cout << de_long_weekday_names[static_cast(wd)] << '\n'; - cout << static_cast(d1.month()) << '/' << d1.day() - << '/' << d1.year() << '\n'; - cout << d1.year() << '-' << d1.month() << '-' << d1.day() << '\n'; - } + // create some gregorian objects to output + auto d1 = 2002_y/oct/1; + auto m = d1.month(); + auto wd = weekday{d1}; + using namespace std; + // output the date in German using short month names + cout << d1.day() << '.' + << setw(2) << static_cast(d1.month()) + << '.' << d1.year() << '\n'; + cout << de_long_month_names[static_cast(m)-1] << '\n'; + cout << de_long_weekday_names[static_cast(wd)] << '\n'; + cout << static_cast(d1.month()) << '/' << d1.day() + << '/' << d1.year() << '\n'; + cout << d1.year() << '-' << d1.month() << '-' << d1.day() << '\n'; +} +``` If your OS supports the `std::locale("de_DE")` the above can be simplified to: +```c++ +#include "date.h" +#include "tz.h" +#include - #include "date.h" - #include "tz.h" - #include +int +main() +{ + using namespace date; - int - main() - { - using namespace date; - - // create some gregorian objects to output - auto d1 = 2002_y/oct/1; - - using namespace std; - locale loc("de_DE"); - cout << format(loc, "%x\n", local_days{d1}); - cout << format(loc, "%B\n", local_days{d1}); - cout << format(loc, "%A\n", local_days{d1}); - cout << format(loc, "%D\n", local_days{d1}); - cout << format(loc, "%F\n", local_days{d1}); - } + // create some gregorian objects to output + auto d1 = 2002_y/oct/1; + using namespace std; + locale loc("de_DE"); + cout << format(loc, "%x\n", local_days{d1}); + cout << format(loc, "%B\n", local_days{d1}); + cout << format(loc, "%A\n", local_days{d1}); + cout << format(loc, "%D\n", local_days{d1}); + cout << format(loc, "%F\n", local_days{d1}); +} +``` ### Date Period Calculations