DateTime Class Reference
#include <datetime.h>
List of all members.
Public Member Functions |
| DateTime () |
| DateTime (int mm, int dd, int yy, int h, int m, string period) throw ( invalid_argument ) |
void | setDate (int mm, int dd, int yy) throw ( invalid_argument ) |
void | setTime (int h, int m, string period) throw ( invalid_argument ) |
void | print (ostream &out=cout) const |
bool | operator== (const DateTime &dt) const |
bool | operator!= (const DateTime &dt) const |
bool | operator< (const DateTime &dt) const |
bool | operator> (const DateTime &dt) 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 ) |
Detailed Description
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].
- Author:
- Mark Maloof (maloof at cs georgetown edu)
- Version:
- 1.1, 11/28/12
Constructor & Destructor Documentation
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.
- Parameters:
-
| 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 greater than or equal to 0 (i.e., 2000) |
| 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" |
- Exceptions:
-
| invalid_argument | if an argument's value is invalid |
Member Function Documentation
bool DateTime::operator!= |
( |
const DateTime & |
dt |
) |
const |
Returns true if this DateTime object is not equal to DateTime object passed as the parameter; returns false otherwise.
- Parameters:
-
- Returns:
- the bool indicating whether the objects are equal
bool DateTime::operator< |
( |
const DateTime & |
dt |
) |
const |
Returns true if this DateTime object is less than (i.e., earlier than) the DateTime object passed as the parameter; returns false otherwise.
- Parameters:
-
- Returns:
- the bool indicating whether this object is less than the parameter
bool DateTime::operator== |
( |
const DateTime & |
dt |
) |
const |
Returns true if this DateTime object is equal to DateTime object passed as the parameter; returns false otherwise.
- Parameters:
-
- Returns:
- the bool indicating whether the objects are equal
bool DateTime::operator> |
( |
const DateTime & |
dt |
) |
const |
Returns true if this DateTime object is greater than (i.e., later than) the DateTime object passed as the parameter; returns false otherwise.
- Parameters:
-
- Returns:
- the bool indicating whether this object is greater than the parameter
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.
- Parameters:
-
| 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 greater than or equal to 0 (i.e., 2000) |
- Exceptions:
-
| 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.
- Parameters:
-
| 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" |
- Exceptions:
-
| invalid_argument | if an argument's value is invalid |
Friends And Related Function Documentation
ostream& operator<< |
( |
ostream & |
out, |
|
|
const DateTime & |
dt | |
|
) |
| | [friend] |
Inserts a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" into the output stream, and returns the modified output stream.
- Parameters:
-
| out | the output stream for insertion |
| dt | the DateTime object for insertion |
- Returns:
- the modified output stream
istream& operator>> |
( |
istream & |
in, |
|
|
DateTime & |
dt | |
|
) |
| | throw ( invalid_argument ) [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.
- Parameters:
-
| in | the input stream for extraction |
| dt | the DateTime object for storing the extracted information |
- Returns:
- the modified input stream
- Exceptions:
-
| invalid_argument | if an argument's value is invalid |
Member Data Documentation
The documentation for this class was generated from the following files: