#include <bdlt_date.h>
This class implements a complex-constrained, value-semantic type for representing dates according to the Unix (POSIX) calendar. Each object of this class always represents a valid date value in the range [0001JAN01 .. 9999DEC31] inclusive. The interface of this class supports Date values expressed in terms of either year/month/day (the canonical representation) or year/day-of-year (an alternate representation). See Valid Date Values and Their Representations for details.
See bdlt_date
|
| | Date () |
| |
| | Date (int year, int dayOfYear) |
| |
| | Date (int year, int month, int day) |
| |
| | Date (const Date &original) |
| |
| | ~Date () |
| |
| Date & | operator= (const Date &rhs) |
| |
| Date & | operator+= (int numDays) |
| |
| Date & | operator-= (int numDays) |
| |
| Date & | operator++ () |
| |
| Date & | operator-- () |
| |
| int | addDaysIfValid (int numDays) |
| |
| void | setYearDay (int year, int dayOfYear) |
| |
| int | setYearDayIfValid (int year, int dayOfYear) |
| |
| void | setYearMonthDay (int year, int month, int day) |
| |
| int | setYearMonthDayIfValid (int year, int month, int day) |
| |
| template<class STREAM > |
| STREAM & | bdexStreamIn (STREAM &stream, int version) |
| |
| int | day () const |
| |
| DayOfWeek::Enum | dayOfWeek () const |
| |
| int | dayOfYear () const |
| |
| void | getYearDay (int *year, int *dayOfYear) const |
| |
| void | getYearMonthDay (int *year, int *month, int *day) const |
| |
| int | month () const |
| |
| MonthOfYear::Enum | monthOfYear () const |
| |
| int | year () const |
| |
| template<class STREAM > |
| STREAM & | bdexStreamOut (STREAM &stream, int version) const |
| |
| bsl::ostream & | print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const |
| |
| bsl::ostream & | streamOut (bsl::ostream &stream) const |
| |
| int | validateAndSetYearDay (int year, int dayOfYear) |
| |
| int | validateAndSetYearMonthDay (int year, int month, int day) |
| |
|
| 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 &) |
| |
| Date | operator+ (const Date &, int) |
| |
| Date | operator+ (int, const Date &) |
| |
| Date | operator- (const Date &, int) |
| |
| int | operator- (const Date &, const Date &) |
| |
| template<class HASHALG > |
| void | hashAppend (HASHALG &hashAlg, const Date &) |
| |
◆ Date() [1/4]
Create a Date object having the earliest supported date value, i.e., having a year/month/day representation of 0001/01/01.
◆ Date() [2/4]
| bdlt::Date::Date |
( |
int |
year, |
|
|
int |
dayOfYear |
|
) |
| |
|
inline |
Create a Date object having the value represented by the specified year and dayOfYear.
- Precondition
- The behavior is undefined unless
year and dayOfYear represent a valid Date value (see isValidYearDay).
◆ Date() [3/4]
| bdlt::Date::Date |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
|
inline |
Create a Date object having the value represented by the specified year, month, and day.
- Precondition
- The behavior is undefined unless
year, month, and day represent a valid Date value (see isValidYearMonthDay).
◆ Date() [4/4]
| bdlt::Date::Date |
( |
const Date & |
original | ) |
|
|
inline |
Create a Date object having the value of the specified original date.
◆ ~Date()
◆ addDaysIfValid()
| int bdlt::Date::addDaysIfValid |
( |
int |
numDays | ) |
|
Set this object to have the value that is later by the specified (signed) numDays from its current value, if the resulting value falls within the range of dates supported by this class (see isValidYearMonthDay). Return 0 on success, and a non-zero value (with no effect) otherwise.
- Note
- Note that
numDays may be negative.
◆ bdexStreamIn()
template<class STREAM >
| STREAM & bdlt::Date::bdexStreamIn |
( |
STREAM & |
stream, |
|
|
int |
version |
|
) |
| |
Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated, but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state.
- Note
- Note that no version is read from
stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
◆ bdexStreamOut()
template<class STREAM >
| STREAM & bdlt::Date::bdexStreamOut |
( |
STREAM & |
stream, |
|
|
int |
version |
|
) |
| const |
Write the value of this object, using the specified version format, to the specified output stream, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated, but otherwise unmodified.
- Note
- Note that
version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
◆ day()
| int bdlt::Date::day |
( |
| ) |
const |
|
inline |
Return the day of the month in the range [1 .. 31] of this date.
◆ dayOfWeek()
◆ dayOfYear()
| int bdlt::Date::dayOfYear |
( |
| ) |
const |
|
inline |
Return the day of the year in the range [1 .. 366] of this date.
◆ getYearDay()
| void bdlt::Date::getYearDay |
( |
int * |
year, |
|
|
int * |
dayOfYear |
|
) |
| const |
|
inline |
Load, into the specified year and dayOfYear, the respective year and dayOfYear attribute values of this date.
◆ getYearMonthDay()
| void bdlt::Date::getYearMonthDay |
( |
int * |
year, |
|
|
int * |
month, |
|
|
int * |
day |
|
) |
| const |
|
inline |
Load, into the specified year, month, and day, the respective year, month, and day attribute values of this date.
◆ isValid() [1/2]
| bool bdlt::Date::isValid |
( |
int |
year, |
|
|
int |
dayOfYear |
|
) |
| |
|
inlinestatic |
Return true if the specified year and dayOfYear represent a valid value for a Date object, and false otherwise. year and dayOfYear represent a valid Date value if they correspond to a valid date as defined by the Unix (POSIX) calendar confined to the year range [1 .. 9999] inclusive. See {Valid Date Values and Their Representations} for details.
- Deprecated:
- Use isValidYearDay instead.
◆ isValid() [2/2]
| bool bdlt::Date::isValid |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
|
inlinestatic |
Return true if the specified year, month, and day represent a valid value for a Date object, and false otherwise. year, month, and day represent a valid Date value if they correspond to a valid date as defined by the Unix (POSIX) calendar confined to the year range [1 .. 9999] inclusive. See {Valid Date Values and Their Representations} for details.
- Deprecated:
- Use isValidYearMonthDay instead.
◆ isValidYearDay()
| bool bdlt::Date::isValidYearDay |
( |
int |
year, |
|
|
int |
dayOfYear |
|
) |
| |
|
inlinestatic |
Return true if the specified year and dayOfYear represent a valid value for a Date object, and false otherwise. year and dayOfYear represent a valid Date value if they correspond to a valid date as defined by the Unix (POSIX) calendar confined to the year range [1 .. 9999] inclusive. See {Valid Date Values and Their Representations} for details.
◆ isValidYearMonthDay()
| bool bdlt::Date::isValidYearMonthDay |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
|
inlinestatic |
Return true if the specified year, month, and day represent a valid value for a Date object, and false otherwise. year, month, and day represent a valid Date value if they correspond to a valid date as defined by the Unix (POSIX) calendar confined to the year range [1 .. 9999] inclusive. See {Valid Date Values and Their Representations} for details.
◆ maxSupportedBdexVersion() [1/2]
| int bdlt::Date::maxSupportedBdexVersion |
( |
| ) |
|
|
inlinestatic |
◆ maxSupportedBdexVersion() [2/2]
| int bdlt::Date::maxSupportedBdexVersion |
( |
int |
versionSelector | ) |
|
|
inlinestatic |
Return the maximum valid BDEX format version, as indicated by the specified versionSelector, to be passed to the bdexStreamOut method.
- Note
- Note that it is highly recommended that
versionSelector be formatted as "YYYYMMDD", a date representation. Also note that versionSelector should be a compile-time-chosen value that selects a format version supported by both externalizer and unexternalizer. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
◆ maxSupportedVersion()
| int bdlt::Date::maxSupportedVersion |
( |
| ) |
|
|
inlinestatic |
◆ month()
| int bdlt::Date::month |
( |
| ) |
const |
|
inline |
Return the month of the year in the range [1 .. 12] of this date.
◆ monthOfYear()
◆ operator++()
| Date & bdlt::Date::operator++ |
( |
| ) |
|
|
inline |
Set this object to have the value that is one day later than its current value, and return a reference providing modifiable access to this object.
- Precondition
- The behavior is undefined if the year/month/day representation of the current value is
9999/12/31.
◆ operator+=()
| Date & bdlt::Date::operator+= |
( |
int |
numDays | ) |
|
|
inline |
Assign to this object the value that is later by the specified (signed) numDays from its current value, and return a reference providing modifiable access to this object.
- Precondition
- The behavior is undefined unless the resulting value falls within the range of dates supported by this class (see
isValidYearMonthDay).
- Note
- Note that
numDays may be negative.
◆ operator--()
| Date & bdlt::Date::operator-- |
( |
| ) |
|
|
inline |
Set this object to have the value that is one day earlier than its current value, and return a reference providing modifiable access to this object.
- Precondition
- The behavior is undefined if the year/month/day representation of the current value is
0001/01/01.
◆ operator-=()
| Date & bdlt::Date::operator-= |
( |
int |
numDays | ) |
|
|
inline |
Assign to this object the value that is earlier by the specified (signed) numDays from its current value, and return a reference providing modifiable access to this object.
- Precondition
- The behavior is undefined unless the resulting value falls within the range of dates supported by this class (see
isValidYearMonthDay).
- Note
- Note that
numDays may be negative.
◆ operator=()
| Date & bdlt::Date::operator= |
( |
const Date & |
rhs | ) |
|
|
inline |
Assign to this object the value of the specified rhs date, and return a reference providing modifiable access to this object.
◆ print()
| bsl::ostream & bdlt::Date::print |
( |
bsl::ostream & |
stream, |
|
|
int |
level = 0, |
|
|
int |
spacesPerLevel = 4 |
|
) |
| const |
Write the value of this object to the specified output stream in a human-readable format, and return a reference to stream. Optionally specify an initial indentation level, whose absolute value is incremented recursively for nested objects. If level is specified, optionally specify spacesPerLevel, whose absolute value indicates the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect.
- Note
- Note that this human-readable format is not fully specified, and can change without notice.
◆ setYearDay()
| void bdlt::Date::setYearDay |
( |
int |
year, |
|
|
int |
dayOfYear |
|
) |
| |
|
inline |
Set this object to have the value represented by the specified year and dayOfYear.
- Precondition
- The behavior is undefined unless
year and dayOfYear represent a valid Date value (see isValidYearDay).
◆ setYearDayIfValid()
| int bdlt::Date::setYearDayIfValid |
( |
int |
year, |
|
|
int |
dayOfYear |
|
) |
| |
|
inline |
Set this object to have the value represented by the specified year and dayOfYear if they comprise a valid Date value (see isValidYearDay). Return 0 on success, and a non-zero value (with no effect) otherwise.
◆ setYearMonthDay()
| void bdlt::Date::setYearMonthDay |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
|
inline |
Set this object to have the value represented by the specified year, month, and day.
- Precondition
- The behavior is undefined unless
year, month, and day represent a valid Date value (see isValidYearMonthDay).
◆ setYearMonthDayIfValid()
| int bdlt::Date::setYearMonthDayIfValid |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
|
inline |
Set this object to have the value represented by the specified year, month, and day if they comprise a valid Date value (see isValidYearMonthDay). Return 0 on success, and a non-zero value (with no effect) otherwise.
◆ streamOut()
| bsl::ostream & bdlt::Date::streamOut |
( |
bsl::ostream & |
stream | ) |
const |
|
inline |
Write the value of this object to the specified output stream in a single-line format, and return a reference to stream. If stream is not valid on entry, this operation has no effect.
- Note
- Note that this human-readable format is not fully specified, can change without notice, and is logically equivalent to:
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
- Deprecated:
- Use print instead.
◆ validateAndSetYearDay()
| int bdlt::Date::validateAndSetYearDay |
( |
int |
year, |
|
|
int |
dayOfYear |
|
) |
| |
|
inline |
Set this object to have the value represented by the specified year and dayOfYear if they comprise a valid Date value (see isValidYearDay). Return 0 on success, and a non-zero value (with no effect) otherwise.
- Deprecated:
- Use setYearDayIfValid instead.
◆ validateAndSetYearMonthDay()
| int bdlt::Date::validateAndSetYearMonthDay |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
|
inline |
Set this object to have the value represented by the specified year, month, and day if they comprise a valid Date value (see isValidYearMonthDay). Return 0 on success, and a non-zero value (with no effect) otherwise.
- Deprecated:
- Use setYearMonthDayIfValid instead.
◆ year()
| int bdlt::Date::year |
( |
| ) |
const |
|
inline |
Return the year in the range [1 .. 9999] of this date.
◆ hashAppend
template<class HASHALG >
| void hashAppend |
( |
HASHALG & |
hashAlg, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Pass the specified object to the specified hashAlg. This function integrates with the bslh modular hashing system and effectively provides a bsl::hash specialization for Date.
◆ operator!=
| bool operator!= |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return true if the specified lhs and rhs objects do not have the same value, and false otherwise. Two Date objects do not have the same value if any of their year, month, and day attributes (respectively) do not have the same value.
◆ operator+ [1/2]
Return the date value that is later by the specified (signed) numDays from the specified date.
- Precondition
- The behavior is undefined unless the resulting value falls within the range of dates supported by this class (see
isValidYearMonthDay).
- Note
- Note that
numDays may be negative.
◆ operator+ [2/2]
◆ operator- [1/2]
| int operator- |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return the (signed) number of days between the specified lhs and rhs dates.
- Note
- Note that if
lhs < rhs the result will be negative.
◆ operator- [2/2]
Return the date value that is earlier by the specified (signed) numDays from the specified date.
- Precondition
- The behavior is undefined unless the resulting value falls within the range of dates supported by this class (see
isValidYearMonthDay).
- Note
- Note that
numDays may be negative.
◆ operator<
| bool operator< |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return true if the specified lhs date is earlier than the specified rhs date, and false otherwise.
◆ operator<=
| bool operator<= |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return true if the specified lhs date is earlier than or the same as the specified rhs date, and false otherwise.
◆ operator==
| bool operator== |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two Date objects have the same value if each of their year, month, and day attributes (respectively) have the same value.
◆ operator>
| bool operator> |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return true if the specified lhs date is later than the specified rhs date, and false otherwise.
◆ operator>=
| bool operator>= |
( |
const Date & |
, |
|
|
const Date & |
|
|
) |
| |
|
friend |
Return true if the specified lhs date is later than or the same as the specified rhs date, and false otherwise.
The documentation for this class was generated from the following file: