Date Generators/Algorithms Date Generators/Algorithms Introduction -- Header -- Class Overview -- Function Overview Introduction Date algorithms or generators are tools for generating other dates or schedules of dates. A generator function starts with some part of a date such as a month and day and is supplied another part to then generate a concrete date. This allows the programmer to represent concepts such as "The first Sunday in February" and then create a concrete set of dates when provided with one or more years. Note: As of boost version 1_31_0, date generator names have been changed. Old names are still available but are no longer documented and may someday be deprecated Also provided are stand-alone functions for generating a date, or calculation a duration of days. These functions take a date object and a weekday object as parameters. All date generator classes and functions are in the boost::gregorian namespace. The print holidays example shows a detailed usage example. Header #include "boost/date_time/date_generators.hpp" Overview Class Construction Parameters get_date Parameter Description Example year_based_generator abstract base class greg_year year A unifying date_generator base type for: partial_date, nth_day_of_the_week_in_month, first_day_of_the_week_in_month, and last_day_of_the_week_in_month The print holidays example shows a detailed usage example. last_day_of_the_week_in_month greg_weekday or weekday, greg_month or month greg_year or year Calculate something like last Monday of January last_day_of_the_week_in_month lwdm(Monday,Jan); date d = lwdm.get_date(2002);//2002-Jan-28 first_day_of_the_week_in_month greg_weekday or weekday, greg_month or month greg_year or year Calculate something like first Monday of January first_day_of_the_week_in_month fdm(Monday,Jan); date d = fdm.get_date(2002);//2002-Jan-07 partial_date greg_day, greg_month or month greg_year Generates a date by applying the year to the given month and day. partial_date pd(1,Jan); date d = pd.get_date(2002);//2002-Jan-01 first_day_of_the_week_after greg_weekday or weekday date Calculate something like First Sunday after Jan 1,2002 first_day_of_the_week_after fdaf(Monday); date d = fdaf.get_date(date(2002,Jan,1));//2002-Jan-07 first_day_of_the_week_before greg_weekday or weekday date Calculate something like First Monday before Feb 1,2002 first_day_of_the_week_before fdbf(Monday); date d = fdbf.get_date(date(2002,Feb,1));//2002-Jan-28 Function Overview Function Prototype Description Example days days_until_weekday (const date&, const greg_weekday&) Calculates the number of days from given date until given weekday. date d(2004,Jun,1); // Tuesday greg_weekday gw(Friday); days_until_weekday(d, gw); // 3 days days days_before_weekday (const date&, const greg_weekday&) Calculates the number of day from given date to previous given weekday. date d(2004,Jun,1); // Tuesday greg_weekday gw(Friday); days_before_weekday(d, gw); // 4 days date next_weekday (const date&, const greg_weekday&) Generates a date object representing the date of the following weekday from the given date. date d(2004,Jun,1); // Tuesday greg_weekday gw(Friday); next_weekday(d, gw); // 2004-Jun-4 date previous_weekday (const date&, const greg_weekday&) Generates a date object representing the date of the previous weekday from the given date. date d(2004,Jun,1); // Tuesday greg_weekday gw(Friday); previous_weekday(d, gw); // 2004-May-28 top