BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt::DateUtil Struct Reference

#include <bdlt_dateutil.h>

Static Public Member Functions

static Date addMonths (const Date &original, int numMonths, bool eomFlag)
 
static Date addMonthsEom (const Date &original, int numMonths)
 
static Date addMonthsNoEom (const Date &original, int numMonths)
 
static Date addYears (const Date &original, int numYears, bool eomFlag)
 
static Date addYearsEom (const Date &original, int numYears)
 
static Date addYearsNoEom (const Date &original, int numYears)
 
static int convertFromYYYYMMDD (Date *result, int yyyymmddValue)
 
static Date convertFromYYYYMMDDRaw (int yyyymmddValue)
 
static int convertToYYYYMMDD (const Date &date)
 
static Date earliestDayOfWeekInMonth (int year, int month, DayOfWeek::Enum dayOfWeek)
 
static bool isValidYYYYMMDD (int yyyymmddValue)
 
static Date lastDayInMonth (int year, int month)
 
static Date lastDayOfWeekInMonth (int year, int month, DayOfWeek::Enum dayOfWeek)
 
static Date nextDayOfWeek (DayOfWeek::Enum dayOfWeek, const Date &date)
 
static Date nextDayOfWeekInclusive (DayOfWeek::Enum dayOfWeek, const Date &date)
 
static Date nthDayOfWeekInMonth (int year, int month, DayOfWeek::Enum dayOfWeek, int n)
 
static Date previousDayOfWeek (DayOfWeek::Enum dayOfWeek, const Date &date)
 
static Date previousDayOfWeekInclusive (DayOfWeek::Enum dayOfWeek, const Date &date)
 

Detailed Description

This struct provides a namespace for utility functions that provide non-primitive operations on dates.

Member Function Documentation

◆ addMonths()

Date bdlt::DateUtil::addMonths ( const Date original,
int  numMonths,
bool  eomFlag 
)
inlinestatic

Return the date that is the specified numMonths from the specified original date, adjusted as necessary according to the specified eomFlag (end-of-month flag). If eomFlag is true and original is the last day of the month, then adjust the result to be the last day of the month; if eomFlag is false, then no such adjustment is performed. In any case, if the day of the month in original does not exist in the month of the result (e.g., February 29, 2001), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numMonths may be negative.

◆ addMonthsEom()

static Date bdlt::DateUtil::addMonthsEom ( const Date original,
int  numMonths 
)
static

Return the date that is the specified numMonths from the specified original date, adjusted as necessary according to the following (end-of-month) rules: (1) if original is the last day of a month, adjust the result to be the last day of the month, and (2) if the day of the month in original does not exist in the month of the result (e.g., February 30), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numMonths may be negative.

◆ addMonthsNoEom()

static Date bdlt::DateUtil::addMonthsNoEom ( const Date original,
int  numMonths 
)
static

Return the date that is the specified numMonths from the specified original date, adjusted as necessary according to the following (non-end-of-month) rule: if the day of the month in original does not exist in the month of the result (e.g., February 29, 2001), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numMonths may be negative.

◆ addYears()

Date bdlt::DateUtil::addYears ( const Date original,
int  numYears,
bool  eomFlag 
)
inlinestatic

Return the date that is the specified numYears from the specified original date, adjusted as necessary according to the specified eomFlag (end-of-month flag). If eomFlag is true and original is the last day of the month, then adjust the result to be the last day of the month; if eomFlag is false, then no such adjustment is performed. In any case, if the day of the month in original does not exist in the month of the result (e.g., February 29, 2001), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numYears may be negative.

◆ addYearsEom()

Date bdlt::DateUtil::addYearsEom ( const Date original,
int  numYears 
)
inlinestatic

Return the date that is the specified numYears from the specified original date, adjusted as necessary according to the following (end-of-month) rules: (1) if original is the last day of a month, adjust the result to be the last day of the month, and (2) if the day of the month in original does not exist in the month of the result (e.g., February 29, 2001), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numYears may be negative.

◆ addYearsNoEom()

Date bdlt::DateUtil::addYearsNoEom ( const Date original,
int  numYears 
)
inlinestatic

Return the date that is the specified numYears from the specified original date, adjusted as necessary according to the following (non-end-of-month) rule: if the day of the month in original does not exist in the month of the result (e.g., February 30), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numYears may be negative.

◆ convertFromYYYYMMDD()

int bdlt::DateUtil::convertFromYYYYMMDD ( Date result,
int  yyyymmddValue 
)
inlinestatic

Load, into the specified result, the Date value represented by the specified yyyymmddValue in the "YYYYMMDD" format. Return 0 on success, and a non-zero value, with no effect on result, if yyyymmddValue does not represent a valid Date.

◆ convertFromYYYYMMDDRaw()

Date bdlt::DateUtil::convertFromYYYYMMDDRaw ( int  yyyymmddValue)
inlinestatic

Return the Date value represented by the specified yyyymmddValue in the "YYYYMMDD" format. The behavior is undefined unless yyyymmddValue represents a valid Date.

◆ convertToYYYYMMDD()

int bdlt::DateUtil::convertToYYYYMMDD ( const Date date)
inlinestatic

Return the integer value in the "YYYYMMDD" format that represents the specified date.

◆ earliestDayOfWeekInMonth()

Date bdlt::DateUtil::earliestDayOfWeekInMonth ( int  year,
int  month,
DayOfWeek::Enum  dayOfWeek 
)
inlinestatic

Return the earliest date in the specified month of the specified year that falls on the specified dayOfWeek. The behavior is undefined unless 1 <= year <= 9999 and 1 <= month <= 12.

◆ isValidYYYYMMDD()

bool bdlt::DateUtil::isValidYYYYMMDD ( int  yyyymmddValue)
inlinestatic

Return true if the specified yyyymmddValue represents a valid Date value in the "YYYYMMDD" format, and false otherwise.

◆ lastDayInMonth()

Date bdlt::DateUtil::lastDayInMonth ( int  year,
int  month 
)
inlinestatic

Return the latest date in the specified month of the specified year. The behavior is undefined unless 1 <= year <= 9999 and 1 <= month <= 12.

◆ lastDayOfWeekInMonth()

static Date bdlt::DateUtil::lastDayOfWeekInMonth ( int  year,
int  month,
DayOfWeek::Enum  dayOfWeek 
)
static

Return the latest date in the specified month of the specified year that falls on the specified dayOfWeek. The behavior is undefined unless 1 <= year <= 9999 and 1 <= month <= 12.

◆ nextDayOfWeek()

static Date bdlt::DateUtil::nextDayOfWeek ( DayOfWeek::Enum  dayOfWeek,
const Date date 
)
static

Return the first date after the specified date that falls on the specified dayOfWeek. The behavior is undefined unless the resulting date is no later than 9999/12/31.

◆ nextDayOfWeekInclusive()

static Date bdlt::DateUtil::nextDayOfWeekInclusive ( DayOfWeek::Enum  dayOfWeek,
const Date date 
)
static

Return the first date on or after the specified date that falls on the specified dayOfWeek. The behavior is undefined unless the resulting date is no later than 9999/12/31.

◆ nthDayOfWeekInMonth()

static Date bdlt::DateUtil::nthDayOfWeekInMonth ( int  year,
int  month,
DayOfWeek::Enum  dayOfWeek,
int  n 
)
static

Return the date in the specified month of the specified year corresponding to the specified nth occurrence of the specified dayOfWeek. If n < 0, return the date corresponding to the -nth occurrence of the dayOfWeek counting from the end of the month towards the first of the month. If 5 == n and a result cannot be found in month, then return the date of the first dayOfWeek in the following month. If -5 == n and a result cannot be found in month, then return the date of the last dayOfWeek in the previous month. The behavior is undefined unless 1 <= year <= 9999, 1 <= month <= 12, n != 0, -5 <= n <= 5, and the resulting date is neither earlier than 0001/01/01 nor later than 9999/12/31.

For example:

static Date nthDayOfWeekInMonth(int year, int month, DayOfWeek::Enum dayOfWeek, int n)
@ e_THURSDAY
Definition bdlt_dayofweek.h:129

returns November 25, 2004, the fourth Thursday in November, 2004.

◆ previousDayOfWeek()

static Date bdlt::DateUtil::previousDayOfWeek ( DayOfWeek::Enum  dayOfWeek,
const Date date 
)
static

Return the last date before the specified date that falls on the specified dayOfWeek. The behavior is undefined unless the resulting date is no earlier than 1/1/1.

◆ previousDayOfWeekInclusive()

static Date bdlt::DateUtil::previousDayOfWeekInclusive ( DayOfWeek::Enum  dayOfWeek,
const Date date 
)
static

Return the last date on or before the specified date that falls on the specified dayOfWeek. The behavior is undefined unless the resulting date is no earlier than 1/1/1.


The documentation for this struct was generated from the following file: