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 main()20main() 21 { 22 using namespace boost::gregorian; 23 24 std::cout << "Enter Year: "; 25 greg_year::value_type year; 26 greg_month::value_type month; 27 std::cin >> year; 28 std::cout << "Enter Month(1..12): "; 29 std::cin >> month; 30 31 try { 32 //Use the calendar to get the last day of the month 33 greg_day::value_type eom_day = gregorian_calendar::end_of_month_day(year,month); 34 date endOfMonth(year,month,eom_day); 35 36 //construct an iterator starting with firt day of the month 37 day_iterator ditr(date(year,month,1)); 38 //loop thru the days and print each one 39 for (; ditr <= endOfMonth; ++ditr) { 40 #if defined(BOOST_DATE_TIME_NO_LOCALE) 41 std::cout << to_simple_string(*ditr) << " [" 42 #else 43 std::cout << *ditr << " [" 44 #endif 45 << ditr->day_of_week() << " week: " 46 << ditr->week_number() << "]" 47 << std::endl; 48 } 49 } 50 catch(std::exception& e) { 51 52 std::cout << "Error bad date, check your entry: \n" 53 << " Details: " << e.what() << std::endl; 54 } 55 return 0; 56 } 57 58 /* Copyright 2001-2004: CrystalClear Software, Inc 59 * http://www.crystalclearsoftware.com 60 * 61 * Subject to the Boost Software License, Version 1.0. 62 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 63 */ 64 65