]>
git.proxmox.com Git - ceph.git/blob - 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
6 * Enter Month(1..12): 2
16 #include "boost/date_time/gregorian/gregorian.hpp"
22 std::cout
<< "Enter Year: ";
25 std::cout
<< "Enter Month(1..12): ";
28 using namespace boost::gregorian
;
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
);
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
) << " ["
41 std::cout
<< *ditr
<< " ["
43 << ditr
->day_of_week() << " week: "
44 << ditr
->week_number() << "]"
48 catch(std::exception
& e
) {
50 std::cout
<< "Error bad date, check your entry: \n"
51 << " Details: " << e
.what() << std::endl
;
56 /* Copyright 2001-2004: CrystalClear Software, Inc
57 * http://www.crystalclearsoftware.com
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)