BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_basicnl365

Detailed Description

Outline

Purpose

Provide stateless functions for the NL/365 convention.

Classes

Description

This component provides a struct, bbldc::BasicNl365, that serves as a namespace for defining a suite of date-related functions used to compute the day count and the year fraction between two dates as per the NL/365 day-count convention. In this day-count convention, we simply measure the number of non-leap days occurring in a time period, and to calculate years, divide that by 365. Note that this means the number of years between January 1, 2004 and January 1, 2005 is 1.0. No end-of-month rule adjustments are made.

Usage

This section illustrates intended use of this component.

Example 1: Computing Day Count and Year Fraction

The following snippets of code illustrate how to use bbldc::BasicNl365 methods. First, create four bdlt::Date variables:

const bdlt::Date dA(2004, 2, 1);
const bdlt::Date dB(2004, 3, 1);
const bdlt::Date dC(2004, 5, 1);
const bdlt::Date dD(2005, 2, 1);
Definition bdlt_date.h:294

Then, compute the day count between some pairs of these dates:

int daysDiff;
daysDiff = bbldc::BasicNl365::daysDiff(dA, dB);
assert( 28 == daysDiff);
daysDiff = bbldc::BasicNl365::daysDiff(dA, dC);
assert( 89 == daysDiff);
daysDiff = bbldc::BasicNl365::daysDiff(dA, dD);
assert(365 == daysDiff);
daysDiff = bbldc::BasicNl365::daysDiff(dB, dC);
assert( 61 == daysDiff);
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)

Finally, compute the year fraction between some of the dates:

double yearsDiff;
yearsDiff = bbldc::BasicNl365::yearsDiff(dA, dC);
// Need fuzzy comparison since 'yearsDiff' is a 'double'.
assert(yearsDiff < 0.2439 && yearsDiff > 0.2438);
yearsDiff = bbldc::BasicNl365::yearsDiff(dA, dD);
assert(1.0 == yearsDiff);
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)
Definition bbldc_basicnl365.h:146