...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Overall Index -- Gregorian Index -- Posix Time Index
Date Generators / Algorithms
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.
using namespace boost::gregorian; typedef boost::date_time::nth_kday_of_month<date> nkday; nkday ldgen(nkday::first, Monday, Sep)); //US labor day date labor_day = ldgen.get_date(2002); //Calculate labor day for 2002
The print holidays example shows a detailed usage example.
#include "boost/date_time/date_generators.hpp"
Class | Construction Parameters | get_date Parameter | Description | Example |
first_kday_after | greg_day_of_week day_of_week | date start_day | Calculate something like First Sunday after Jan 1,2002 | first_kday_after fkaf(Monday); date d = fkaf.get_date(date(2002,Jan,1));//2002-Jan-07 |
first_kday_before | greg_day_of_week day_of_week | date start_day | Calculate something like First Monday before Feb 1,2002 | first_kday_before fkbf(Monday); date d = fkbf.get_date(date(2002,Feb,1));//2002-Jan-28 |
last_kday_of_month | greg_day_of_week day_of_week greg_month month |
greg_year year | Calculate something like last Monday of January | last_kday_of_month lkm(Monday,Jan); date d = lkm.get_date(2002);//2002-Jan-28 |
first_kday_of_month | greg_day_of_week day_of_week greg_month month |
greg_year year | Calculate something like first Monday of January | first_kday_of_month fkm(Monday,Jan); date d = fkm.get_date(2002);//2002-Jan-07 |
partial_date | greg_day day_of_month greg_month month |
greg_year 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 |