]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/xmldoc/ex_find_last_day_of_months.xml
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / date_time / xmldoc / ex_find_last_day_of_months.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
3 "../../../tools/boostbook/dtd/boostbook.dtd">
4
5 <!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
6 Subject to the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 -->
9
10 <section id="date_time.examples.end_of_month_day">
11 <title>Last Day of the Months</title>
12
13 <para>
14 Example that gets a month and a year from the user and finds the last day of each remaining month of that year.
15 </para>
16 <programlisting>
17 <![CDATA[
18 /* Simple program that finds the last day of the given month,
19 * then displays the last day of every month left in the given year.
20 */
21
22 #include "boost/date_time/gregorian/gregorian.hpp"
23 #include <iostream>
24
25 int
26 main()
27 {
28 using namespace boost::gregorian;
29
30 greg_year year(1400);
31 greg_month month(1);
32
33 // get a month and a year from the user
34 try {
35 int y, m;
36 std::cout << " Enter Year(ex: 2002): ";
37 std::cin >> y;
38 year = greg_year(y);
39 std::cout << " Enter Month(1..12): ";
40 std::cin >> m;
41 month = greg_month(m);
42 }
43 catch(bad_year by) {
44 std::cout << "Invalid Year Entered: " << by.what() << '\n'
45 << "Using minimum values for month and year." << std::endl;
46 }
47 catch(bad_month bm) {
48 std::cout << "Invalid Month Entered" << bm.what() << '\n'
49 << "Using minimum value for month. " << std::endl;
50 }
51
52 date start_of_next_year(year+1, Jan, 1);
53 date d(year, month, 1);
54
55 // add another month to d until we enter the next year.
56 while (d < start_of_next_year){
57 std::cout << to_simple_string(d.end_of_month()) << std::endl;
58 d += months(1);
59 }
60
61 return 0;
62 }
63
64 ]]>
65 </programlisting>
66 </section>