| 1 | // |
| 2 | // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // https://www.boost.org/LICENSE_1_0.txt |
| 6 | |
| 7 | #include <boost/locale.hpp> |
| 8 | #include <ctime> |
| 9 | #include <iomanip> |
| 10 | #include <iostream> |
| 11 | |
| 12 | int main() |
| 13 | { |
| 14 | using namespace boost::locale; |
| 15 | |
| 16 | generator gen; |
| 17 | std::locale::global(loc: gen("" )); |
| 18 | std::cout.imbue(loc: std::locale()); |
| 19 | // Setup environment |
| 20 | |
| 21 | boost::locale::date_time now; |
| 22 | |
| 23 | date_time start = now; |
| 24 | |
| 25 | // Set the first day of the first month of this year |
| 26 | start.set(f: period::month(), v: now.minimum(f: period::month())); |
| 27 | start.set(f: period::day(), v: start.minimum(f: period::day())); |
| 28 | |
| 29 | const int current_year = period::year(dt: now); |
| 30 | |
| 31 | // Display current year |
| 32 | std::cout << format("{1,ftime='%Y'}" ) % now << std::endl; |
| 33 | |
| 34 | // Run forward until current year is the date |
| 35 | for(now = start; period::year(dt: now) == current_year;) { |
| 36 | // Print heading of month |
| 37 | if(calendar().is_gregorian()) |
| 38 | std::cout << format("{1,ftime='%B'}" ) % now << std::endl; |
| 39 | else |
| 40 | std::cout << format("{1,ftime='%B'} ({1,ftime='%Y-%m-%d',locale=en} - {2,locale=en,ftime='%Y-%m-%d'})" ) |
| 41 | % now % date_time(now, now.maximum(f: period::day()) * period::day()) |
| 42 | << std::endl; |
| 43 | |
| 44 | const int first = calendar().first_day_of_week(); |
| 45 | |
| 46 | // Print week days |
| 47 | for(int i = 0; i < 7; i++) { |
| 48 | date_time tmp(now, period::day_of_week() * (first + i)); |
| 49 | std::cout << format("{1,w=8,ftime='%a'} " ) % tmp; |
| 50 | } |
| 51 | std::cout << std::endl; |
| 52 | |
| 53 | const int current_month = now / period::month(); |
| 54 | const int skip = now / period::day_of_week_local() - 1; |
| 55 | for(int i = 0; i < skip * 9; i++) |
| 56 | std::cout << ' '; |
| 57 | for(; now / period::month() == current_month; now += period::day()) { |
| 58 | std::cout << format("{1,w=8,ftime='%e'} " ) % now; |
| 59 | if(now / period::day_of_week_local() == 7) |
| 60 | std::cout << std::endl; |
| 61 | } |
| 62 | std::cout << std::endl; |
| 63 | } |
| 64 | } |
| 65 | |