Date Class Reference
Date and time calculations

Concrete date class. More...

`#include <ql/time/date.hpp>`

## Public Types

typedef boost::int_fast32_t | serial_type
| serial number type

## Public Member Functions

constructors
| Date ()
| Default constructor returning a null date.
| Date (Date::serial_type serialNumber)
| Constructor taking a serial number as given by Applix or Excel.
| Date (Day d, Month m, Year y)
| More traditional constructor.
inspectors
Weekday | weekday () const
Day | dayOfMonth () const
Day | dayOfYear () const
| One-based (Jan 1st = 1)
Month | month () const
Year | year () const
Date::serial_type | serialNumber () const
date algebra
Date & | operator+= (Date::serial_type days)
| increments date by the given number of days
Date & | operator+= (const Period &)
| increments date by the given period
Date & | operator-= (Date::serial_type days)
| decrement date by the given number of days
Date & | operator-= (const Period &)
| decrements date by the given period
Date & | operator++ ()
| 1-day pre-increment
Date | operator++ (int)
| 1-day post-increment
Date & | operator-- ()
| 1-day pre-decrement
Date | operator-- (int)
| 1-day post-decrement
Date | operator+ (Date::serial_type days) const
| returns a new date incremented by the given number of days
Date | operator+ (const Period &) const
| returns a new date incremented by the given period
Date | operator- (Date::serial_type days) const
| returns a new date decremented by the given number of days
Date | operator- (const Period &) const
| returns a new date decremented by the given period

## Related Functions

(Note that these are not member functions.)
Date::serial_type | operator- (const Date &, const Date &)
| Difference in days between dates.
Time | daysBetween (const Date &, const Date &)
| Difference in days (including fraction of days) between dates.
bool | operator== (const Date &, const Date &)
bool | operator!= (const Date &, const Date &)
bool | operator< (const Date &, const Date &)
bool | operator<= (const Date &, const Date &)
bool | operator> (const Date &, const Date &)
bool | operator>= (const Date &, const Date &)
std::size_t | hash_value (const Date &d)
std::ostream & | operator<< (std::ostream &, const Date &)

## static methods

static Date | todaysDate ()
| today's date.
static Date | minDate ()
| earliest allowed date
static Date | maxDate ()
| latest allowed date
static bool | isLeap (Year y)
| whether the given year is a leap one
static Date | endOfMonth (const Date &d)
| last day of the month to which the given date belongs
static bool | isEndOfMonth (const Date &d)
| whether a date is the last day of its month
static Date | nextWeekday (const Date &d, Weekday w)
| next given weekday following or equal to the given date More...
static Date | nthWeekday (Size n, Weekday w, Month m, Year y)
| n-th given weekday in the given month and year More...

## Detailed Description

Concrete date class.

This class provides methods to inspect dates as well as methods and operators which implement a limited date algebra (increasing and decreasing dates, and calculating their difference).

Tests:
  self-consistency of dates, serial numbers, days of month, months, and weekdays is checked over the whole date range.

Examples
  BasketLosses.cpp, BermudanSwaption.cpp, Bonds.cpp, CallableBonds.cpp, CDS.cpp, ConvertibleBonds.cpp, CVAIRS.cpp, DiscreteHedging.cpp, EquityOption.cpp, FittedBondCurve.cpp, FRA.cpp, Gaussian1dModels.cpp, LatentModel.cpp, MulticurveBootstrapping.cpp, Replication.cpp, and Repo.cpp.

## Member Function Documentation

## nextWeekday()

static Date nextWeekday | ( | const Date & | d,
|  | Weekday | w
| ) |  |

static

next given weekday following or equal to the given date

E.g., the Friday following Tuesday, January 15th, 2002 was January 18th, 2002.

see http://www.cpearson.com/excel/DateTimeWS.htm

## nthWeekday()

static Date nthWeekday | ( | Size | n,
|  | Weekday | w,
|  | Month | m,
|  | Year | y
| ) |  |

static

n-th given weekday in the given month and year

E.g., the 4th Thursday of March, 1998 was March 26th, 1998.

see http://www.cpearson.com/excel/DateTimeWS.htm

## Friends And Related Function Documentation

## hash_value()

std::size_t hash_value | ( | const Date & | d | ) |

related

Compute a hash value of `d`.

This method makes Date hashable via `boost::hash`.

Example:

#include <boost/unordered_set.hpp>
boost::unordered_set<Date> set;
Date d = Date(1, Jan, 2020);
set.insert(d);
assert(set.count(d)); // 'd' was added to 'set'

Parameters

  [in] | d | Date to hash

Returns
  A hash value of `d`