1 /* Generate a set of dates using a collection of date generators
14 #include "boost/date_time/gregorian/gregorian.hpp"
22 print_date(boost::gregorian::date d
)
24 using namespace boost::gregorian
;
25 #if defined(BOOST_DATE_TIME_NO_LOCALE)
26 std::cout
<< to_simple_string(d
) << " [" << d
.day_of_week() << "]\n";
28 std::cout
<< d
<< " [" << d
.day_of_week() << "]\n";
36 std::cout
<< "Enter Year: ";
40 using namespace boost::gregorian
;
42 //define a collection of holidays fixed by month and day
43 std::vector
<year_based_generator
*> holidays
;
44 holidays
.push_back(new partial_date(1,Jan
)); //Western New Year
45 holidays
.push_back(new partial_date(4,Jul
)); //US Independence Day
46 holidays
.push_back(new partial_date(25, Dec
));//Christmas day
49 //define a shorthand for the nth_day_of_the_week_in_month function object
50 typedef nth_day_of_the_week_in_month nth_dow
;
53 holidays
.push_back(new nth_dow(nth_dow::first
, Monday
, Sep
));
55 holidays
.push_back(new nth_dow(nth_dow::third
, Monday
, Jan
));
57 holidays
.push_back(new nth_dow(nth_dow::second
, Tuesday
, Feb
));
59 holidays
.push_back(new nth_dow(nth_dow::fourth
, Thursday
, Nov
));
61 typedef std::set
<date
> date_set
;
62 date_set all_holidays
;
64 for(std::vector
<year_based_generator
*>::iterator it
= holidays
.begin();
65 it
!= holidays
.end(); ++it
)
67 all_holidays
.insert((*it
)->get_date(year
));
70 //print the holidays to the screen
71 std::for_each(all_holidays
.begin(), all_holidays
.end(), print_date
);
72 std::cout
<< "Number Holidays: " << all_holidays
.size() << std::endl
;
77 /* Copyright 2001-2004: CrystalClear Software, Inc
78 * http://www.crystalclearsoftware.com
80 * Subject to the Boost Software License, Version 1.0.
81 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)