]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/example/gregorian/find_last_day_of_months.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / date_time / example / gregorian / find_last_day_of_months.cpp
1 /* Simple program that finds the last day of the given month,
2 * then displays the last day of every month left in the given year.
3 */
4
5 #include "boost/date_time/gregorian/gregorian.hpp"
6 #include <iostream>
7
8 int
9 main()
10 {
11 using namespace boost::gregorian;
12
13 greg_year year(1400);
14 greg_month month(1);
15
16 // get a month and a year from the user
17 try {
18 int y, m;
19 std::cout << " Enter Year(ex: 2002): ";
20 std::cin >> y;
21 year = greg_year(y);
22 std::cout << " Enter Month(1..12): ";
23 std::cin >> m;
24 month = greg_month(m);
25 }
26 catch(bad_year by) {
27 std::cout << "Invalid Year Entered: " << by.what() << '\n'
28 << "Using minimum values for month and year." << std::endl;
29 }
30 catch(bad_month bm) {
31 std::cout << "Invalid Month Entered" << bm.what() << '\n'
32 << "Using minimum value for month. " << std::endl;
33 }
34
35 date start_of_next_year(year+1, Jan, 1);
36 date d(year, month, 1);
37
38 // add another month to d until we enter the next year.
39 while (d < start_of_next_year){
40 std::cout << to_simple_string(d.end_of_month()) << std::endl;
41 d += months(1);
42 }
43
44 return 0;
45 }
46
47 /* Copyright 2001-2005: CrystalClear Software, Inc
48 * http://www.crystalclearsoftware.com
49 *
50 * Subject to the Boost Software License, Version 1.0.
51 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
52 */
53