QuantLib
A free/open-source library for quantitative finance
Fully annotated sources - version 1.22
Public Types | Related Functions | List of all members
Date Class Reference

Concrete date class. More...

#include <ql/time/date.hpp>

+ Collaboration diagram for Date:

Public Types

typedef boost::int_fast32_t serial_type
 serial number type More...
 

Public Member Functions

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

Related Functions

(Note that these are not member functions.)

Date::serial_type operator- (const Date &, const Date &)
 Difference in days between dates. More...
 
Time daysBetween (const Date &, const Date &)
 Difference in days (including fraction of days) between dates. More...
 
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

Date::serial_type serialNumber_
 
static Date todaysDate ()
 today's date. More...
 
static Date minDate ()
 earliest allowed date More...
 
static Date maxDate ()
 latest allowed date More...
 
static bool isLeap (Year y)
 whether the given year is a leap one More...
 
static Date endOfMonth (const Date &d)
 last day of the month to which the given date belongs More...
 
static bool isEndOfMonth (const Date &d)
 whether a date is the last day of its month More...
 
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...
 
static Date::serial_type minimumSerialNumber ()
 
static Date::serial_type maximumSerialNumber ()
 
static void checkSerialNumber (Date::serial_type serialNumber)
 
static Date advance (const Date &d, Integer units, TimeUnit)
 
static Integer monthLength (Month m, bool leapYear)
 
static Integer monthOffset (Month m, bool leapYear)
 
static Date::serial_type yearOffset (Year y)
 

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.

Definition at line 125 of file date.hpp.

Member Typedef Documentation

◆ serial_type

typedef boost::int_fast32_t serial_type

serial number type

Definition at line 128 of file date.hpp.

Constructor & Destructor Documentation

◆ Date() [1/3]

Date ( )

Default constructor returning a null date.

Definition at line 57 of file date.cpp.

+ Here is the caller graph for this function:

◆ Date() [2/3]

Date ( Date::serial_type  serialNumber)
explicit

Constructor taking a serial number as given by Applix or Excel.

Definition at line 60 of file date.cpp.

+ Here is the call graph for this function:

◆ Date() [3/3]

Date ( Day  d,
Month  m,
Year  y 
)

More traditional constructor.

Definition at line 65 of file date.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ weekday()

Weekday weekday ( ) const
Examples
Bonds.cpp, FRA.cpp, and MulticurveBootstrapping.cpp.

Definition at line 385 of file date.hpp.

+ Here is the caller graph for this function:

◆ dayOfMonth()

Day dayOfMonth ( ) const

Definition at line 390 of file date.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dayOfYear()

Day dayOfYear ( ) const

One-based (Jan 1st = 1)

Definition at line 394 of file date.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ month()

Month month ( ) const

Definition at line 81 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ year()

Year year ( ) const

Definition at line 92 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialNumber()

Date::serial_type serialNumber ( ) const

Definition at line 398 of file date.hpp.

+ Here is the caller graph for this function:

◆ operator+=() [1/2]

Date & operator+= ( Date::serial_type  days)

increments date by the given number of days

Definition at line 100 of file date.cpp.

+ Here is the call graph for this function:

◆ operator+=() [2/2]

Date & operator+= ( const Period p)

increments date by the given period

Definition at line 107 of file date.cpp.

+ Here is the call graph for this function:

◆ operator-=() [1/2]

Date & operator-= ( Date::serial_type  days)

decrement date by the given number of days

Definition at line 112 of file date.cpp.

+ Here is the call graph for this function:

◆ operator-=() [2/2]

Date & operator-= ( const Period p)

decrements date by the given period

Definition at line 119 of file date.cpp.

+ Here is the call graph for this function:

◆ operator++() [1/2]

Date & operator++ ( )

1-day pre-increment

Definition at line 124 of file date.cpp.

+ Here is the call graph for this function:

◆ operator++() [2/2]

Date operator++ ( int  )

1-day post-increment

Definition at line 760 of file date.cpp.

◆ operator--() [1/2]

Date & operator-- ( )

1-day pre-decrement

Definition at line 131 of file date.cpp.

+ Here is the call graph for this function:

◆ operator--() [2/2]

Date operator-- ( int  )

1-day post-decrement

Definition at line 766 of file date.cpp.

◆ operator+() [1/2]

Date operator+ ( Date::serial_type  days) const

returns a new date incremented by the given number of days

Definition at line 402 of file date.hpp.

+ Here is the call graph for this function:

◆ operator+() [2/2]

Date operator+ ( const Period p) const

returns a new date incremented by the given period

Definition at line 410 of file date.hpp.

+ Here is the call graph for this function:

◆ operator-() [1/2]

Date operator- ( Date::serial_type  days) const

returns a new date decremented by the given number of days

Definition at line 406 of file date.hpp.

+ Here is the call graph for this function:

◆ operator-() [2/2]

Date operator- ( const Period p) const

returns a new date decremented by the given period

Definition at line 414 of file date.hpp.

+ Here is the call graph for this function:

◆ todaysDate()

Date todaysDate ( )
static

today's date.

Examples
ConvertibleBonds.cpp, and DiscreteHedging.cpp.

Definition at line 772 of file date.cpp.

+ Here is the caller graph for this function:

◆ minDate()

Date minDate ( )
static

earliest allowed date

Definition at line 750 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maxDate()

Date maxDate ( )
static

latest allowed date

Definition at line 755 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLeap()

bool isLeap ( Year  y)
static

whether the given year is a leap one

Definition at line 186 of file date.cpp.

+ Here is the caller graph for this function:

◆ endOfMonth()

Date endOfMonth ( const Date d)
static

last day of the month to which the given date belongs

Definition at line 418 of file date.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEndOfMonth()

bool isEndOfMonth ( const Date d)
static

whether a date is the last day of its month

Definition at line 424 of file date.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextWeekday()

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

Definition at line 781 of file date.cpp.

◆ nthWeekday()

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

Definition at line 786 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minimumSerialNumber()

Date::serial_type minimumSerialNumber ( )
staticprivate

Definition at line 733 of file date.cpp.

+ Here is the caller graph for this function:

◆ maximumSerialNumber()

Date::serial_type maximumSerialNumber ( )
staticprivate

Definition at line 737 of file date.cpp.

+ Here is the caller graph for this function:

◆ checkSerialNumber()

void checkSerialNumber ( Date::serial_type  serialNumber)
staticprivate

Definition at line 741 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ advance()

Date advance ( const Date d,
Integer  units,
TimeUnit  units 
)
staticprivate

Definition at line 138 of file date.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monthLength()

Integer monthLength ( Month  m,
bool  leapYear 
)
staticprivate

Definition at line 258 of file date.cpp.

+ Here is the caller graph for this function:

◆ monthOffset()

Integer monthOffset ( Month  m,
bool  leapYear 
)
staticprivate

Definition at line 268 of file date.cpp.

+ Here is the caller graph for this function:

◆ yearOffset()

Date::serial_type yearOffset ( Year  y)
staticprivate

Definition at line 282 of file date.cpp.

+ Here is the caller graph for this function: