Go to the previous, next section.
#include <nihcl/Date.h>
Instances of Class
Date
represent Gregorian calendar dates. The Gregorian calendar began on October 5, 1582, but was not adopted by Great Britain and her American colonies until September 14, 1752. Class
Date
does not check for pre-Gregorian dates.
Class
Date
provides a complete set of calendar functions, including computing a date some number of days before or after another, calculating the number of days between two dates, and determining the day of the week a particular date falls on.
Member functions of class
Date
use the following data types:
typedef unsigned short dayTy; typedef unsigned short monthTy; typedef unsigned short yearTy; typedef unsigned long julTy; // Julian day number
Class
Date
follows the convention that the days of the week are numbered from 1 to 7 beginning with 1 = Monday, days of the month and year are numbered beginning at 1, and months are numbered from 1 to 12.
static dayTy dayOfWeek(const char*
dayName)
dayOfWeek("Monday")
is 1 and
dayOfWeek("Sun")
is 7. The
dayName
may be abbreviated to three characters and may be upper or lower case. If the name is invalid an
NIHCL_BADDAYNAM
exception is raised.
static bool dayWithinMonth(monthTy
month, dayTy
day, yearTy
year)
YES
if
day
is a valid day in the specified
month
and
year. For example,
dayWithinMonth(2, 29, 1988)
is
YES
and
dayWithinMonth(2, 29, 1989)
is
NO
.
static dayTy daysInYear(yearTy
year)
static julTy jday(monthTy
m, dayTy
d, yearTy
y)
static bool leapYear(yearTy
year)
YES
if
year
is a leap year.
static const char* nameOfDay(dayTy
weekDayNumber)
nameOfDay(1)
returns a pointer to the character string
"Monday"
and
nameOfDay(7)
returns a pointer to the character string
"Sunday"
. Raises the exception
NIHCL_BADDAY
if
weekDayNumber
is > 7.
static const char* nameOfMonth(monthTy
monthNumber)
nameOfMonth(1)
returns a pointer to the character string
"January"
and
nameOfMonth(12)
returns a pointer to the character string
"December"
. Raises
NIHCL_BADMONTH
if
monthNumber
is > 12.
static monthTy numberOfMonth(const char*
monthName)
numberOfMonth("FEB")
returns 2.
Date()
Date
for today's date.
Date(long
dayCount)
Date
for
dayCount
days before (dayCount
< 0) or after (dayCount
> 0) January 1, 1901. For example,
Date(-1)
is December 31, 1900 and
Date(1)
is January 2, 1901.
Date(long
dayCount, yearTy
referenceYear)
Date
for the
dayCount
day of the
referenceYear. Note that
dayCount
may be larger than 365, and may also be zero or negative, in which case the constructed
Date
is that of a year after or before the
referenceYear, respectively. For example
Date(367, 1984)
is January 1, 1985, and
Date(-1, 1984)
is December 30, 1983.
Date(dayTy
newDay, const char*
monthName, yearTy
newYear)
Date
for the specified day of month, month, and year. If an invalid day of month is specified, for example
Date(29, "Feb", 1985)
, an
NIHCL_BADMODAY
exception is raised.
Date(istream&
strm)
Date
by parsing input from input stream
strm. The date may be in any of the following three formats:
MM/DD/YY 3/10/86 DD-MMM-YY 10-MAR-86 MMM DD, YY March 10, 1986
Month names may be abbreviated to three characters, and may be in upper or lower case. Years from 00 to 99 are interpreted as 1900 to 1999, and any non-alphanumeric characters may be used as delimiters.
friend Date operator+(const Date&
dt, int
dd)
friend Date operator+(int
dd, const Date&
dt)
Date
that is
dd
days after the
Date
dt
if
dd
is positive, or
dd
days before
dt
if
dd
is negative.
Date operator-(int
dd) const
Date
that is
dd
days before this
Date
if
dd
is positive, or
dd
days after this
Date
if
dd
is negative.
int operator-(const Date&) const
Date
and the argument
Date
. The result is negative if the argument
Date
is later than this
Date
.
void operator+=(int
dd)
Date
by one that is
dd
days after this
Date
if
dd
is positive, or
dd
days before this
Date
if
dd
is negative.
void operator-=(int
dd)
Date
by one that is
dd
days before this
Date
if
dd
is positive, or
dd
days after this
Date
if
dd
is negative.
bool operator<(const Date&) const
bool operator<=(const Date&) const
bool operator>(const Date&) const
bool operator>=(const Date&) const
bool operator==(const Date&) const
bool operator!=(const Date&) const
YES
if the indicated relation holds between this
Date
and the argument
Date
.
Date max(const Date&
dt) const
Date
and the argument
Date
.
Date min(const Date&
dt) const
Date
and the argument
Date
.
virtual int compare(const Object&
ob) const
Date
with the argument object
ob, which must also be an instance of class
Date
. Returns a negative result if this
Date
is earlier than
ob, zero if this
Date
equals
ob, and a positive result if this
Date
is later than
ob.
bool between(const Date&
min, const Date&
max) const
YES
if this
Date
is later than or equal to
min
and earlier than or equal to
max.
bool leap() const
YES
if this
Date
is a leap year.
virtual bool isEqual(const Object&
ob) const
YES
if
ob
is of species
Date
and equals this
Date
.
dayTy day() const
Date
. For example,
Date(1,"Jan",1986).day()
is 1, and
Date(1,"Mar",1986).day()
is 60.
dayTy dayOfMonth() const
Date
. For example,
Date(1,"Mar",1986).day() is 1.
dayTy firstDayOfMonth() const
Date
. For example,
Date(10,"March",1986).firstDayOfMonth()
is 60.
dayTy firstDayOfMonth(monthTy
month) const
Date
. For example,
Date(10,"March",1986).firstDayOfMonth(2)
is 32.
void mdy(monthTy&
m, dayTy&
d, yearTy&
y) const
Date
.
monthTy month() const
Date
's month. For example,
Date(10,"Mar",86)
is 3.
const char* nameOfMonth() const
Date
's month. For example,
Date(10,"MAR",86).nameOfMonth()
is a pointer to the string
"March"
.
Date previous(const char*
dayName) const
Date
of the last weekday named
dayName
prior to or on this
Date
. For example, the date of the last Sunday in April in the year 1984 can be calculated by the expression:
Date(30,"APR",1984).previous("Sun")
dayTy weekDay() const
Date
.
yearTy year() const
Date
.
virtual unsigned hash() const
virtual void deepenShallowCopy()
Date
.
virtual void printOn(ostream&
strm
=cout) const
Date
on the output stream
strm
in the format DD-MMM-YY.
virtual void scanFrom(istream&
strm)
Date
by that read from the input stream
strm. The format is the same as that described for the constructor
Date(istream&)
.
virtual const Class* species() const
Date
.
virtual void storer(OIOofd&
fd) const
virtual void storer(OIOout&
strm) const
Date
on
fd
or
strm.
NIHCL_BADMODAY
,
NIHCL_BADDAYNAM
,
NIHCL_BADMONAM
,
NIHCL_BADMONTH
,
NIHCL_BADDAY
,
NIHCL_RDFAIL
Go to the previous, next section.