PtDate is a class which is used to represent dates. This class is registered in the type manager.
It is not generally safe to derive your class from a class which is registered in the type manager. You may create a date class which contains a PtDate, but you may not derive a class from PtDate.
Files to include | Class declaration | Base class |
poet.hxx | ptcomp.hxx | none |
PtDaysOfTheWeek | enum PtDaysOfTheWeek{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}; |
constructor | PtDate(); |
destructor | ~PtDate(); |
Day | char& Day(); |
DayOfTheDate | PtDaysOfTheWeek DayOfTheDate(); |
IsDate | int IsDate(); |
IsLastDayOfTheMonth | int IsLastDayOfTheMonth(); |
Month | char& Month(); |
PrintDayOfTheDate | PtString PrintDayOfTheDate(); |
Today | PtDate& Today(); |
Year | short& Year(); |
operator + | PtDate operator + (long days); |
operator - | PtDate operator - (long days); |
operator ++ | PtDate& operator ++ (); |
operator - - | PtDate& operator -- (); |
operator += | PtDate& operator += (long days); |
operator -= | PtDate& operator -= (long days); |
operator = | PtDate& operator = (PtDate& ); |
operator < | int operator < (PtDate& ); |
operator > | int operator > (PtDate& ); |
operator == | int operator == (PtDate& ); |
operator != | int operator != (PtDate& ); |
operator long | operator long(); |
- PtDate::PtDate()
- PtDate:: PtDate(short year, char month, char day)
PtDate:: PtDate(long StartDate)
PtDate:: PtDate(PtDate& ThatDate)
Each of these declarations is discussed separately below.
- PtDate::PtDate()
Constructor. Sets day, month, and year to the current date.
- PtDate:: PtDate(short year, char month, char day)
Constructor. Sets day, month, and year to the values from the parameter list.
- PtDate:: PtDate(long StartDate)
Constructor. StartDate is treated as the number of days since January 1, 4713 B.C. PtDate uses Julian dates internally..
- PtDate:: PtDate(PtDate& ThatDate)
Copy constructor. Sets the value of this date to ThatDate.
- PtDate::~PtDate()
Destructor. It is not virtual since you are not supposed to derive other classes from PtDate or other type manager types.
- char& PtDate::Day()
Accesses the day for the date. May be used to get or set the day.
- PtDate date;
- date.Day() = 10;
- cout << (int) date.Day(); // Must cast!
The above cast is necessary to make cout print the day as an integer. PtDate:: Day() returns a character.
- PtDaysOfTheWeek PtDate::DayOfTheDate()
Returns the day of the week for the date contained in this PtDate object.
- PtDate date (1991, (char) 12, (char) 12);
- PtDaysOfTheWeek Day;
- Day = date.DayOfTheDate();
- int PtDate::IsDate()
Returns a non-zero value if the date is valid; returns zero if the date is invalid.
- int PtDate::IsLastDayOfTheMonth()
Return a non-zero value if the date is the last day of the month.
- char& PtDate::Month()
Access the month of the date. May be used to get or set the month.
- PtDate date;
- date.Month() = 10;
- cout << (int) date.Month();
The above cast is necessary to make cout print the month as an integer. PtDate:: Month() returns a character.
- PtString PtDate::PrintDayOfTheDate()
Returns the name of the current weekday as a PtString.
- PtDate& PtDate::Today()
- short& PtDate::Year()
Access the year of the date. May be used to get or set the year.
- PtDate date;
- date.Year() = 1991;
- cout << date.Year();
- PtDate PtDate ::operator + (long days)
- PtDate result;
- PtDate date (1990, (char) 9, (char) 9);
- result = date + 5; // Add 5 days
- PtDate PtDate::operator - (long days) long PtDate::operator - (PtDate& ThatDate)
Subtraction operator. The first form subtracts days from a date to return another date. The second form returns the number of days between two dates.
- PtDate dateA (1991, (char) 9, (char) 9);
- PtDate dateB (1991, (char) 10, (char) 9);
- long days;
- days = dateB - dateA; // uses long PtDate::operator -(PtDate&)
- dateB = dateA - 10; // uses PtDate PtDate::operator -(long days)
- PtDate& PtDate::operator ++ ()
Increments the date by one day.
- PtDate date (1991, (char) 12, (char) 24);
- ++date;
- PtDate& PtDate::operator -- ()
Decrements the date by one day.
- PtDate date (1991, (char) 12, (char) 26);
- --date;
- PtDate& PtDate::operator += (long days)
Adds some number of days to the date.
- PtDate date (1991, (char) 12, (char) 26);
- date += 7;
- PtDate& PtDate::operator -= (long days)
Subtracts some number of days from the date.
- PtDate date (1991, (char) 12, (char) 26);
- date -= 7;
- PtDate& PtDate::operator = (const PtDate& )
Assignment operator. Assigns one date to another.
- PtDate date (1991, (char) 12, (char) 26);
- PtDate result;
- result = date;
- int PtDate::operator < (PtDate& )
Comparison operator. Returns a non-zero value if date A is less than date B.
- PtDate dateA;
- PtDate dateB;
- // Compare
- if (dateA < dateB)
- {
- cout << "dateA is less." << endl;
- }
- int PtDate::operator > (PtDate& )
Comparison operator. Returns a non-zero value if date A is greater than date B.
- PtDate dateA;
- PtDate dateB;
- if (dateA > dateB)
- {
- cout << "dateA is greater." << endl;
- }
- int PtDate::operator == (PtDate& )
Comparison operator. Returns a non-zero value if date A is equal to date B.
- PtDate dateA;
- PtDate dateB;
- if (dateA == dateB)
- {
- cout << "Well, Margaret, they look the same to me." << endl;
- }
- int PtDate::operator != (PtDate& )
Comparison operator. Returns a non-zero value if date A is not equal to date B.
-1 | if a > b |
1 | if a < b |
0 | if a == b |
- PtDate HireDay;
- PtDate FixedDay;
- switch ( HireDay != FixedDay )
- {
- case -1 :
- case 0 :
- cout << "Hired before fixed day";
- break;
- case 1 :
- cout << "Hired later":
- break;
- }
- PtDate::operator long()
The number of days since January 1, 4713 B.C.
This enum is used to represent the day of the week.
Copyright (c) 1996 POET Software, Inc. All rights reserved. Reproduction in whole or in part in any form or medium without the express permission of POET Software, Inc. is prohibited.