Public Member Functions | Private Attributes | Friends | List of all members
DateTime Class Reference

#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 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

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.

Parameters
mmthe month, an int value in [1, 12]
ddthe day, an int value in [1, 28, 30, 31], depending on the month
yythe year, an int value in [0, 99]
hthe hour, an int value in [1, 12]
mthe minute, an int value in [0, 59]
periodthe period, a string value of either "AM" or "PM"
Exceptions
invalid_argumentif 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
dtthe DateTime object to be compared
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
dtthe DateTime object to be compared
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
dtthe DateTime object to be compared
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
dtthe DateTime object to be compared
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
mmthe month, an int value in [1, 12]
ddthe day, an int value in [1, 28, 30, 31], depending on the month
yythe year, an int value in [0, 99]
Exceptions
invalid_argumentif 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
hthe hour, an int value in [1, 12]
mthe minute, an int value in [0, 59]
periodthe period, a string value of either "AM" or "PM"
Exceptions
invalid_argumentif 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
outthe output stream for insertion
dtthe 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
inthe input stream for extraction
dtthe DateTime object for storing the extracted information
Returns
the modified input stream
Exceptions
invalid_argumentif an argument's value is invalid

Member Data Documentation

int DateTime::dd
private

the day of the month

int DateTime::h
private

the hour of the day

int DateTime::m
private

the minute of the hour

int DateTime::mm
private

the month of the year

string DateTime::period
private

the period of the day

int DateTime::yy
private

the year


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