OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TDate Class Reference

The TDate class represents a date. More...

#include <owl/date.h>

Public Types

enum  HowToPrint { Normal , Terse , Numbers , EuropeanNumbers , European , WinIntSection }
 Lists different print formats. More...
 
enum  TDateType { dtMonthNames , dtUCMonthNames , dtWeekDayNames , dtUCWeekDayNames }
 

Public Member Functions

 TDate ()
 Construct a TDate with the current date.
 
 TDate (DayTy day, YearTy year)
 Construct a TDate with a given day of the year and a given year.
 
 TDate (DayTy, const tstring &month, YearTy)
 Construct a TDate for the given day, month, and year.
 
 TDate (DayTy, MonthTy, YearTy)
 Construct a TDate for the given day, month, and year.
 
 TDate (const tistream &s)
 Read date from stream.
 
 TDate (const TTime &)
 Construct a TDate from a TTime.
 
 TDate (const TSystemTime &)
 Construct a TDate from a TSystemTime.
 
 TDate (LPCTSTR str, LPCTSTR format=nullptr)
 
 TDate (const tstring &s)
 
 TDate (const tstring &s, const tstring &format)
 
TSystemTime GetSystemTime () const
 
tstring AsString () const
 Converts the TDate object to a string object.
 
int Between (const TDate &d1, const TDate &d2) const
 Returns 1 if this TDate object is between d1 and d2, inclusive.
 
int CompareTo (const TDate &) const
 Returns 1 if the target TDate is greater than parameter TDate, -1 if the target is less than the parameter, and 0 if the dates are equal.
 
DayTy Day () const
 Returns the day of the year (1-365).
 
int DaysInMonth (MonthTy month=0) const
 
DayTy DayOfMonth () const
 Returns the day (1-31) of the month of this TDate.
 
DayTy FirstDayOfMonth () const
 Returns the number of the first day of the month for this TDate.
 
DayTy FirstDayOfMonth (MonthTy) const
 Return the number of the first day of a given month Return 0 if "month" is outside of the range 1 through 12, inclusive.
 
unsigned Hash () const
 Returns a hash value for the date.
 
int IsValid () const
 Returns 1 if this TDate is valid, 0 otherwise.
 
int Leap () const
 leap year?
 
TDate Max (const TDate &dt) const
 Compares this TDate with dt and returns the date with the greater Julian number.
 
TDate Min (const TDate &dt) const
 Compares this TDate with dt and returns the date with the lesser Julian number.
 
MonthTy Month () const
 Returns the month of this TDate.
 
LPCTSTR NameOfDay () const
 Returns this TDate's day string name.
 
LPCTSTR NameOfMonth () const
 Returns this TDate's month string name.
 
TDate Previous (const tstring &dayName) const
 Return date of previous dayName.
 
TDate Previous (DayTy) const
 Same as above, but use day of week.
 
DayTy WeekDay (DayTy day=0) const
 Returns 1 (Monday) through 7 (Sunday).
 
YearTy Year () const
 Returns the year of this TDate.
 
int operator< (const TDate &date) const
 Returns 1 if this TDate precedes date. Otherwise returns 0.
 
int operator<= (const TDate &date) const
 Returns 1 if this TDate is less than or equal to date, otherwise returns 0.
 
int operator> (const TDate &date) const
 Returns 1 if this TDate is greater than date. otherwise returns 0.
 
int operator>= (const TDate &date) const
 Returns 1 if this TDate is greater than or equal to date, otherwise returns 0.
 
int operator== (const TDate &date) const
 Returns 1 if this TDate is equal to date, otherwise returns 0.
 
int operator!= (const TDate &date) const
 Returns 1 if this TDate is not equal to date, otherwise returns 0.
 
JulTy operator- (const TDate &dt) const
 Subtracts dt from this TDate and returns the difference.
 
void operator++ ()
 Increments this TDate by 1.
 
void operator-- ()
 Decrements this TDate by 1.
 
void operator+= (int dd)
 Adds dd to this TDate.
 
void operator-= (int dd)
 Subtracts dd from this TDate.
 

Static Public Member Functions

static LPCTSTR DayName (DayTy weekDayNumber)
 Returns a string name for the weekday number.
 
static DayTy DayOfWeek (const tstring &dayName)
 Return the number, 1-7, of the day of the week named nameOfDay.
 
static int DayWithinMonth (MonthTy, DayTy, YearTy)
 Returns 1 if the given day (1-31) is within the given month for the given year.
 
static DayTy DaysInYear (YearTy)
 Returns the number of days in the year specified (365 or 366).
 
static MonthTy IndexOfMonth (const tstring &monthName)
 Returns the number, 1-12, of the month named nameOfMonth.
 
static JulTy Jday (MonthTy, DayTy, YearTy)
 Convert Gregorian calendar date to the corresponding Julian day number j.
 
static int LeapYear (YearTy year)
 
static LPCTSTR MonthName (MonthTy monthNumber)
 Returns the string name for the given monthNumber (1-12).
 
static HowToPrint SetPrintOption (HowToPrint h)
 Sets the print option for all TDate objects and returns the old setting.
 
static void SetIntlNames (TDateType type, const tchar **names)
 
static const tcharGetIntlName (TDateType type, int index)
 

Static Protected Member Functions

static int AssertWeekDayNumber (DayTy d)
 Returns 1 if d is between 1 and 7 inclusive, otherwise returns 0.
 
static int AssertIndexOfMonth (MonthTy m)
 Returns 1 if m is between 1 and 12 inclusive, otherwise returns 0.
 

Friends

TDate operator+ (const TDate &dt, int dd)
 Returns a new TDate containing the sum of this TDate and dd.
 
TDate operator+ (int dd, const TDate &dt)
 Returns a new TDate containing the sum of this TDate and dd.
 
TDate operator- (const TDate &dt, int dd)
 
tostreamoperator<< (tostream &s, const TDate &d)
 Inserts date into output stream os.
 
tistreamoperator>> (tistream &s, TDate &d)
 Extracts date from input stream is.
 
opstreamoperator<< (opstream &s, const TDate &d)
 
ipstreamoperator>> (ipstream &s, TDate &d)
 

Detailed Description

The TDate class represents a date.

It has members that read, write, and store dates, and that convert dates to Gregorian calendar dates.

Definition at line 48 of file date.h.

Member Enumeration Documentation

◆ HowToPrint

Lists different print formats.

Enumerator
Normal 
Terse 
Numbers 
EuropeanNumbers 
European 
WinIntSection 

Definition at line 52 of file date.h.

◆ TDateType

Enumerator
dtMonthNames 
dtUCMonthNames 
dtWeekDayNames 
dtUCWeekDayNames 

Definition at line 151 of file date.h.

Constructor & Destructor Documentation

◆ TDate() [1/10]

owl::TDate::TDate ( )

Construct a TDate with the current date.

Constructs a TDate object with the current date.

Definition at line 68 of file date.cpp.

References Jday(), and owl::TSystemTime::LocalTime().

◆ TDate() [2/10]

owl::TDate::TDate ( DayTy day,
YearTy year )

Construct a TDate with a given day of the year and a given year.

Constructs a TDate object with the given day and year.

The base date for this computation is Dec. 31 of the previous year. If year == 0, Construct a TDate with Jan. 1, 1901 as the "day zero". i.e., TDate(-1,0) = Dec. 31, 1900 and TDate(1,0) = Jan. 2, 1901.

The base date for this computation is December 31 of the previous year. If year == 0, it constructs a TDate with January 1, 1901, as the "day zero." For example, TDate(-1,0) = December 31, 1900, and TDate(1,0) = January 2, 1901.

Definition at line 84 of file date.cpp.

References Jday().

◆ TDate() [3/10]

owl::TDate::TDate ( DayTy day,
const tstring & month,
YearTy year )

Construct a TDate for the given day, month, and year.

Construct a TDate for the given day, monthName, and year.

Definition at line 95 of file date.cpp.

References IndexOfMonth(), and Jday().

◆ TDate() [4/10]

owl::TDate::TDate ( DayTy day,
MonthTy month,
YearTy year )

Construct a TDate for the given day, month, and year.

Definition at line 103 of file date.cpp.

References Jday().

◆ TDate() [5/10]

owl::TDate::TDate ( const tistream & s)
inline

Read date from stream.

Constructs a TDate object, reading the date from input stream is.

Definition at line 189 of file date.h.

◆ TDate() [6/10]

owl::TDate::TDate ( const TTime & t)

Construct a TDate from a TTime.

Type conversion to date.

Definition at line 111 of file date.cpp.

References owl::TTime::IsValid(), and owl::SECONDS_IN_DAY.

◆ TDate() [7/10]

owl::TDate::TDate ( const TSystemTime & t)

Construct a TDate from a TSystemTime.

Definition at line 119 of file date.cpp.

References owl::TSystemTime::GetDay(), owl::TSystemTime::GetMonth(), owl::TSystemTime::GetYear(), and Jday().

◆ TDate() [8/10]

owl::TDate::TDate ( LPCTSTR str,
LPCTSTR format = nullptr )
inline

Definition at line 194 of file date.h.

◆ TDate() [9/10]

owl::TDate::TDate ( const tstring & s)
inline

Definition at line 79 of file date.h.

◆ TDate() [10/10]

owl::TDate::TDate ( const tstring & s,
const tstring & format )
inline

Definition at line 80 of file date.h.

Member Function Documentation

◆ AssertIndexOfMonth()

int owl::TDate::AssertIndexOfMonth ( MonthTy m)
inlinestaticprotected

Returns 1 if m is between 1 and 12 inclusive, otherwise returns 0.

Definition at line 308 of file date.h.

◆ AssertWeekDayNumber()

int owl::TDate::AssertWeekDayNumber ( DayTy d)
inlinestaticprotected

Returns 1 if d is between 1 and 7 inclusive, otherwise returns 0.

Definition at line 302 of file date.h.

◆ AsString()

tstring owl::TDate::AsString ( ) const

Converts the TDate object to a string object.

Definition at line 29 of file dateio.cpp.

◆ Between()

int owl::TDate::Between ( const TDate & d1,
const TDate & d2 ) const
inline

Returns 1 if this TDate object is between d1 and d2, inclusive.

Definition at line 200 of file date.h.

◆ CompareTo()

int owl::TDate::CompareTo ( const TDate & d) const

Returns 1 if the target TDate is greater than parameter TDate, -1 if the target is less than the parameter, and 0 if the dates are equal.

Definition at line 279 of file date.cpp.

◆ Day()

DayTy owl::TDate::Day ( ) const

Returns the day of the year (1-365).

Definition at line 292 of file date.cpp.

References Jday(), and Year().

◆ DayName()

const tchar * owl::TDate::DayName ( DayTy weekDayNumber)
static

Returns a string name for the weekday number.

Monday == 1, ... , Sunday == 7 Return 0 for weekday number out of range

Definition at line 146 of file date.cpp.

References AssertWeekDayNumber().

◆ DayOfMonth()

DayTy owl::TDate::DayOfMonth ( ) const

Returns the day (1-31) of the month of this TDate.

Definition at line 300 of file date.cpp.

◆ DayOfWeek()

DayTy owl::TDate::DayOfWeek ( const tstring & nameOfDay)
static

Return the number, 1-7, of the day of the week named nameOfDay.

Return 0 if name doesn't match.

Definition at line 155 of file date.cpp.

References owl::FindMatch().

◆ DaysInMonth()

int owl::TDate::DaysInMonth ( MonthTy month = 0) const

Definition at line 162 of file date.cpp.

References AssertIndexOfMonth(), Leap(), and Month().

◆ DaysInYear()

DayTy owl::TDate::DaysInYear ( YearTy year)
static

Returns the number of days in the year specified (365 or 366).

Definition at line 194 of file date.cpp.

References LeapYear().

◆ DayWithinMonth()

int owl::TDate::DayWithinMonth ( MonthTy month,
DayTy day,
YearTy year )
static

Returns 1 if the given day (1-31) is within the given month for the given year.

Definition at line 181 of file date.cpp.

References AssertIndexOfMonth(), and LeapYear().

◆ FirstDayOfMonth() [1/2]

DayTy owl::TDate::FirstDayOfMonth ( ) const
inline

Returns the number of the first day of the month for this TDate.

Definition at line 206 of file date.h.

References FirstDayOfMonth(), and Month().

◆ FirstDayOfMonth() [2/2]

DayTy owl::TDate::FirstDayOfMonth ( MonthTy month) const

Return the number of the first day of a given month Return 0 if "month" is outside of the range 1 through 12, inclusive.

Definition at line 311 of file date.cpp.

References AssertIndexOfMonth(), and Leap().

◆ GetIntlName()

const tchar * owl::TDate::GetIntlName ( TDateType type,
int index )
static

Definition at line 530 of file date.cpp.

◆ GetSystemTime()

TSystemTime owl::TDate::GetSystemTime ( ) const

Definition at line 128 of file date.cpp.

References WeekDay().

◆ Hash()

unsigned owl::TDate::Hash ( ) const

Returns a hash value for the date.

Definition at line 322 of file date.cpp.

◆ IndexOfMonth()

MonthTy owl::TDate::IndexOfMonth ( const tstring & nameOfMonth)
static

Returns the number, 1-12, of the month named nameOfMonth.

Return 0 for no match.

Definition at line 203 of file date.cpp.

References owl::FindMatch().

◆ IsValid()

int owl::TDate::IsValid ( ) const
inline

Returns 1 if this TDate is valid, 0 otherwise.

Definition at line 212 of file date.h.

◆ Jday()

JulTy owl::TDate::Jday ( MonthTy m,
DayTy d,
YearTy y )
static

Convert Gregorian calendar date to the corresponding Julian day number j.

Algorithm 199 from Communications of the ACM, Volume 6, No. 8, (Aug. 1963), p. 444. Gregorian calendar started on Sep. 14, 1752. This function not valid before that. Returns 0 if the date is invalid.

Definition at line 215 of file date.cpp.

References DayWithinMonth().

◆ Leap()

int owl::TDate::Leap ( ) const
inline

leap year?

Returns 1 if this TDate's year is a leap year, 0 otherwise.

Definition at line 218 of file date.h.

References LeapYear(), and Year().

◆ LeapYear()

int owl::TDate::LeapYear ( YearTy year)
static

Definition at line 240 of file date.cpp.

◆ Max()

TDate owl::TDate::Max ( const TDate & dt) const

Compares this TDate with dt and returns the date with the greater Julian number.

Definition at line 361 of file date.cpp.

◆ Min()

TDate owl::TDate::Min ( const TDate & dt) const

Compares this TDate with dt and returns the date with the lesser Julian number.

Definition at line 370 of file date.cpp.

◆ Month()

MonthTy owl::TDate::Month ( ) const

Returns the month of this TDate.

Definition at line 379 of file date.cpp.

◆ MonthName()

const tchar * owl::TDate::MonthName ( MonthTy monthNumber)
static

Returns the string name for the given monthNumber (1-12).

Returns 0 for an invalid monthNumber.

Definition at line 249 of file date.cpp.

References AssertIndexOfMonth().

◆ NameOfDay()

LPCTSTR owl::TDate::NameOfDay ( ) const
inline

Returns this TDate's day string name.

Definition at line 224 of file date.h.

References DayName(), and WeekDay().

◆ NameOfMonth()

LPCTSTR owl::TDate::NameOfMonth ( ) const
inline

Returns this TDate's month string name.

Definition at line 230 of file date.h.

References Month(), and MonthName().

◆ operator!=()

int owl::TDate::operator!= ( const TDate & date) const
inline

Returns 1 if this TDate is not equal to date, otherwise returns 0.

Definition at line 266 of file date.h.

◆ operator++()

void owl::TDate::operator++ ( )
inline

Increments this TDate by 1.

Definition at line 278 of file date.h.

◆ operator+=()

void owl::TDate::operator+= ( int dd)
inline

Adds dd to this TDate.

Definition at line 290 of file date.h.

◆ operator-()

JulTy owl::TDate::operator- ( const TDate & dt) const
inline

Subtracts dt from this TDate and returns the difference.

Definition at line 272 of file date.h.

◆ operator--()

void owl::TDate::operator-- ( )
inline

Decrements this TDate by 1.

Definition at line 284 of file date.h.

◆ operator-=()

void owl::TDate::operator-= ( int dd)
inline

Subtracts dd from this TDate.

Definition at line 296 of file date.h.

◆ operator<()

int owl::TDate::operator< ( const TDate & date) const
inline

Returns 1 if this TDate precedes date. Otherwise returns 0.

Definition at line 236 of file date.h.

◆ operator<=()

int owl::TDate::operator<= ( const TDate & date) const
inline

Returns 1 if this TDate is less than or equal to date, otherwise returns 0.

Definition at line 242 of file date.h.

◆ operator==()

int owl::TDate::operator== ( const TDate & date) const
inline

Returns 1 if this TDate is equal to date, otherwise returns 0.

Definition at line 260 of file date.h.

◆ operator>()

int owl::TDate::operator> ( const TDate & date) const
inline

Returns 1 if this TDate is greater than date. otherwise returns 0.

Definition at line 248 of file date.h.

◆ operator>=()

int owl::TDate::operator>= ( const TDate & date) const
inline

Returns 1 if this TDate is greater than or equal to date, otherwise returns 0.

Definition at line 254 of file date.h.

◆ Previous() [1/2]

TDate owl::TDate::Previous ( const tstring & dayName) const

Return date of previous dayName.

Returns the TDate of the previous dayName.

Definition at line 390 of file date.cpp.

References DayOfWeek(), and Previous().

◆ Previous() [2/2]

TDate owl::TDate::Previous ( DayTy desiredDayOfWeek) const

Same as above, but use day of week.

Returns the TDate of the previous day.

Definition at line 399 of file date.cpp.

References TDate(), and WeekDay().

◆ SetIntlNames()

void owl::TDate::SetIntlNames ( TDateType type,
const tchar ** names )
static

Definition at line 511 of file date.cpp.

◆ SetPrintOption()

TDate::HowToPrint owl::TDate::SetPrintOption ( HowToPrint h)
static

Sets the print option for all TDate objects and returns the old setting.

Definition at line 39 of file dateio.cpp.

◆ WeekDay()

DayTy owl::TDate::WeekDay ( DayTy day = 0) const

Returns 1 (Monday) through 7 (Sunday).

Definition at line 422 of file date.cpp.

References Jday(), Month(), and Year().

◆ Year()

YearTy owl::TDate::Year ( ) const

Returns the year of this TDate.

Definition at line 431 of file date.cpp.

Friends And Related Symbol Documentation

◆ operator+ [1/2]

TDate operator+ ( const TDate & dt,
int dd )
friend

Returns a new TDate containing the sum of this TDate and dd.

Definition at line 541 of file date.cpp.

◆ operator+ [2/2]

TDate operator+ ( int dd,
const TDate & dt )
friend

Returns a new TDate containing the sum of this TDate and dd.

Definition at line 549 of file date.cpp.

◆ operator-

TDate operator- ( const TDate & dt,
int dd )
friend

Definition at line 557 of file date.cpp.

◆ operator<< [1/2]

opstream & operator<< ( opstream & s,
const TDate & d )
friend

Definition at line 14 of file datep.cpp.

◆ operator<< [2/2]

tostream & operator<< ( tostream & s,
const TDate & d )
friend

Inserts date into output stream os.

Definition at line 184 of file dateio.cpp.

◆ operator>> [1/2]

ipstream & operator>> ( ipstream & s,
TDate & d )
friend

Definition at line 19 of file datep.cpp.

◆ operator>> [2/2]

tistream & operator>> ( tistream & s,
TDate & d )
friend

Extracts date from input stream is.

Definition at line 240 of file dateio.cpp.


The documentation for this class was generated from the following files: