#include <datetime.h>
Public Member Functions | |
DateTime () | |
DateTime (int mm, int dd, int yy, int h, int m, string period) throw ( invalid_argument ) | |
bool | operator== (const DateTime &dt) const |
bool | operator!= (const DateTime &dt) const |
bool | operator< (const DateTime &dt) const |
bool | operator> (const DateTime &dt) const |
void | print (ostream &out=cout) const |
void | setDate (int mm, int dd, int yy) throw ( invalid_argument ) |
void | setTime (int h, int m, string period) throw ( invalid_argument ) |
Private Member Functions | |
unsigned long | toLong () const |
Private Attributes | |
int | mm |
int | dd |
int | yy |
int | h |
int | m |
string | period |
Friends | |
ostream & | operator<< (ostream &out, const DateTime &dt) |
istream & | operator>> (istream &in, DateTime &dt) throw ( invalid_argument ) |
A class for storing dates and times. Dates are in the format MM/DD/YY, and times are in the twelve-hour format, HH:MM [AM|PM].
DateTime::DateTime | ( | ) |
Default constructor. Sets a defalt object to "01/01/00 12:00 AM".
DateTime::DateTime | ( | int | mm, |
int | dd, | ||
int | yy, | ||
int | h, | ||
int | m, | ||
string | period | ||
) | |||
throw | ( | invalid_argument | |
) |
Explicit constructor. Sets the date and time to the passed values. Throws an exception if passed invalid values.
mm | the month, an int value in [1, 12] |
dd | the day, an int value in [1, 28, 30, 31], depending on the month |
yy | the year, an int value in [0, 99] |
h | the hour, an int value in [1, 12] |
m | the minute, an int value in [0, 59] |
period | the period, a string value of either "AM" or "PM" |
invalid_argument | if an argument's value is invalid |
bool DateTime::operator!= | ( | const DateTime & | dt | ) | const |
bool DateTime::operator< | ( | const DateTime & | dt | ) | const |
bool DateTime::operator== | ( | const DateTime & | dt | ) | const |
bool DateTime::operator> | ( | const DateTime & | dt | ) | const |
void DateTime::print | ( | ostream & | out = cout | ) | const |
void DateTime::setDate | ( | int | mm, |
int | dd, | ||
int | yy | ||
) | |||
throw | ( | invalid_argument | |
) |
Sets the date portion of this object. Throws an exception if passed invalid values.
mm | the month, an int value in [1, 12] |
dd | the day, an int value in [1, 28, 30, 31], depending on the month |
yy | the year, an int value in [0, 99] |
invalid_argument | if an argument's value is invalid |
void DateTime::setTime | ( | int | h, |
int | m, | ||
string | period | ||
) | |||
throw | ( | invalid_argument | |
) |
Sets the time porition of this object. Throws an exception if passed invalid values.
h | the hour, an int value in [1, 12] |
m | the minute, an int value in [0, 59] |
period | the period, a string value of either "AM" or "PM" |
invalid_argument | if an argument's value is invalid |
|
private |
Converts a date to an unsigned long for the purpose of comparison. Implementing this method is optional, as there are other methods for comparing dates.
|
friend |
|
friend |
Extracts a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" from the input stream, and returns the modified input stream. Sets the fail bit of the input stream if the object is improperly formatted. Throws an exception if a value is invalid.
in | the input stream for extraction |
dt | the DateTime object for storing the extracted information |
invalid_argument | if an argument's value is invalid |
|
private |
the day of the month
|
private |
the hour of the day
|
private |
the minute of the hour
|
private |
the month of the year
|
private |
the period of the day
|
private |
the year