QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
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 std::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, CDS.cpp, CVAIRS.cpp, CallableBonds.cpp, ConvertibleBonds.cpp, DiscreteHedging.cpp, EquityOption.cpp, FRA.cpp, FittedBondCurve.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 std::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 58 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 61 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 66 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 395 of file date.hpp.

+ Here is the caller graph for this function:

◆ dayOfMonth()

Day dayOfMonth ( ) const

Definition at line 400 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 404 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 82 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 93 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 408 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 101 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 108 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 113 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 120 of file date.cpp.

+ Here is the call graph for this function:

◆ operator++() [1/2]

Date & operator++ ( )

1-day pre-increment

Definition at line 125 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 776 of file date.cpp.

◆ operator--() [1/2]

Date & operator-- ( )

1-day pre-decrement

Definition at line 132 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 782 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 412 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 420 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 416 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 424 of file date.hpp.

+ Here is the call graph for this function:

◆ todaysDate()

Date todaysDate ( )
static

today's date.

Definition at line 788 of file date.cpp.

+ Here is the caller graph for this function:

◆ minDate()

Date minDate ( )
static

earliest allowed date

Definition at line 766 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 771 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 187 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 428 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 434 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 797 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 802 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 749 of file date.cpp.

+ Here is the caller graph for this function:

◆ maximumSerialNumber()

Date::serial_type maximumSerialNumber ( )
staticprivate

Definition at line 753 of file date.cpp.

+ Here is the caller graph for this function:

◆ checkSerialNumber()

void checkSerialNumber ( Date::serial_type  serialNumber)
staticprivate

Definition at line 757 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
Examples
FRA.cpp, and FittedBondCurve.cpp.

Definition at line 139 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 259 of file date.cpp.

+ Here is the caller graph for this function:

◆ monthOffset()

Integer monthOffset ( Month  m,
bool  leapYear 
)
staticprivate

Definition at line 269 of file date.cpp.

+ Here is the caller graph for this function:

◆ yearOffset()

Date::serial_type yearOffset ( Year  y)
staticprivate

Definition at line 283 of file date.cpp.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator-()

Date::serial_type operator- ( const Date ,
const Date  
)
related

Difference in days between dates.

Definition at line 438 of file date.hpp.

+ Here is the call graph for this function:

◆ daysBetween()

Time daysBetween ( const Date ,
const Date  
)
related

Difference in days (including fraction of days) between dates.

Definition at line 442 of file date.hpp.

◆ operator==()

bool operator== ( const Date ,
const Date  
)
related

Definition at line 446 of file date.hpp.

+ Here is the call graph for this function:

◆ operator!=()

bool operator!= ( const Date ,
const Date  
)
related

Definition at line 450 of file date.hpp.

+ Here is the call graph for this function:

◆ operator<()

bool operator< ( const Date ,
const Date  
)
related

Definition at line 454 of file date.hpp.

+ Here is the call graph for this function:

◆ operator<=()

bool operator<= ( const Date ,
const Date  
)
related

Definition at line 458 of file date.hpp.

+ Here is the call graph for this function:

◆ operator>()

bool operator> ( const Date ,
const Date  
)
related

Definition at line 462 of file date.hpp.

+ Here is the call graph for this function:

◆ operator>=()

bool operator>= ( const Date ,
const Date  
)
related

Definition at line 466 of file date.hpp.

+ Here is the call graph for this function:

◆ 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 <unordered_set>
std::unordered_set<Date> set;
Date d = Date(1, Jan, 2020);
set.insert(d);
assert(set.count(d)); // 'd' was added to 'set'
Concrete date class.
Definition: date.hpp:125
Date()
Default constructor returning a null date.
Definition: date.cpp:58
@ Jan
Definition: date.hpp:69
Parameters
[in]dDate to hash
Returns
A hash value of d

Definition at line 846 of file date.cpp.

+ Here is the call graph for this function:

◆ operator<<()

std::ostream & operator<< ( std::ostream &  ,
const Date  
)
related

Definition at line 859 of file date.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ serialNumber_

Date::serial_type serialNumber_
private

Definition at line 253 of file date.hpp.