]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/example/gregorian/print_month.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / date_time / example / gregorian / print_month.cpp
1 /* This example prints all the dates in a month. It demonstrates
2 * the use of iterators as well as functions of the gregorian_calendar
3 *
4 * Output:
5 * Enter Year: 2002
6 * Enter Month(1..12): 2
7 * 2002-Feb-01 [Fri]
8 * 2002-Feb-02 [Sat]
9 * 2002-Feb-03 [Sun]
10 * 2002-Feb-04 [Mon]
11 * 2002-Feb-05 [Tue]
12 * 2002-Feb-06 [Wed]
13 * 2002-Feb-07 [Thu]
14 */
15
16 #include "boost/date_time/gregorian/gregorian.hpp"
17 #include <iostream>
18
19 int
20 main()
21 {
22 std::cout << "Enter Year: ";
23 int year, month;
24 std::cin >> year;
25 std::cout << "Enter Month(1..12): ";
26 std::cin >> month;
27
28 using namespace boost::gregorian;
29 try {
30 //Use the calendar to get the last day of the month
31 int eom_day = gregorian_calendar::end_of_month_day(year,month);
32 date endOfMonth(year,month,eom_day);
33
34 //construct an iterator starting with firt day of the month
35 day_iterator ditr(date(year,month,1));
36 //loop thru the days and print each one
37 for (; ditr <= endOfMonth; ++ditr) {
38 #if defined(BOOST_DATE_TIME_NO_LOCALE)
39 std::cout << to_simple_string(*ditr) << " ["
40 #else
41 std::cout << *ditr << " ["
42 #endif
43 << ditr->day_of_week() << " week: "
44 << ditr->week_number() << "]"
45 << std::endl;
46 }
47 }
48 catch(std::exception& e) {
49
50 std::cout << "Error bad date, check your entry: \n"
51 << " Details: " << e.what() << std::endl;
52 }
53 return 0;
54 }
55
56 /* Copyright 2001-2004: CrystalClear Software, Inc
57 * http://www.crystalclearsoftware.com
58 *
59 * Subject to the Boost Software License, Version 1.0.
60 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
61 */
62