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