Project 1
|
#include <datetime.h>
Public Member Functions | |
DateTime () | |
DateTime (int mm, int dd, int yy, int h, int m, string period) | |
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 | setDate (int mm, int dd, int yy) |
void | setTime (int h, int m, string period) |
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) |
ostream & | operator<< (ostream &out, const DateTime &dt) |
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 | ||
) |
Explicit constructor. Sets the date and time to the passed values. Indirectly 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::setDate | ( | int | mm, |
int | dd, | ||
int | yy | ||
) |
Sets the date portion of this object. Directly 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 | ||
) |
Sets the time porition of this object. Directly 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 DateTime object to an unsigned long for the purpose of comparison. Implementing this method is optional, as there are other methods for comparing dates and times.
|
friend |
|
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. Indirectly throws an exception if a value in the stream 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