Date Generators/AlgorithmsDate 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"
OverviewClassConstruction Parametersget_date ParameterDescriptionExampleyear_based_generatorabstract base classgreg_year yearA 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_monthgreg_weekday or weekday, greg_month or monthgreg_year or yearCalculate 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_monthgreg_weekday or weekday, greg_month or monthgreg_year or yearCalculate 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_dategreg_day, greg_month or monthgreg_yearGenerates 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 weekdaydateCalculate 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 weekdaydateCalculate 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 OverviewFunction PrototypeDescriptionExampledays 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