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)
void setDate (int mm, int dd, int yy)
void setTime (int h, int m, string period)
void read (istream &in)
void write (ostream &out) const
void writeln (ostream &out) const
void print (ostream &out=cout) const
void println (ostream &out=cout) const
string toString () 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)


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@cs)
Version:
1.0, 1/8/10

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 
)

Explicit constructor. Sets the date and time to the passed 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"


Member Function Documentation

void DateTime::setDate ( int  mm,
int  dd,
int  yy 
)

Sets the date portion of this object. Fails silently by not setting values that are out of range.

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)

void DateTime::setTime ( int  h,
int  m,
string  period 
)

Sets the time porition of this object. Fails silently by not setting values that are out of range.

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"

void DateTime::read ( istream &  in  ) 

Reads a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" from the input stream. Sets the fail bit of the input stream if the object is improperly formatted.

Parameters:
in the input stream for reading

void DateTime::write ( ostream &  out  )  const

Writes a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" to the output stream without an end-of-line character.

Parameters:
out the output stream for writing

void DateTime::writeln ( ostream &  out  )  const

Writes a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" to the output stream with an end-of-line character.

Parameters:
out the output stream for writing

void DateTime::print ( ostream &  out = cout  )  const

Prints a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" to the output stream without an end-of-line character.

Parameters:
out the output stream for writing

void DateTime::println ( ostream &  out = cout  )  const

Prints a DateTime object in the format "MM/DD/YY HH:MM [AM|PM]" to the output stream with an end-of-line character.

Parameters:
out the output stream for writing

string DateTime::toString (  )  const

Returns the string representation of this DateTime object in the format "MM/DD/YY HH:MM [AM|PM]".

Returns:
the string representation of this DateTime object

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:
dt the 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 not equal to DateTime object passed as the parameter; returns false otherwise.

Parameters:
dt the 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:
dt the 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 greater than (i.e., later than) the DateTime object passed as the parameter; returns false otherwise.

Parameters:
dt the DateTime object to be compared
Returns:
the bool indicating whether this object is greater than the parameter


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 
) [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.

Parameters:
in the input stream for extraction
dt the DateTime object for storing the extracted information
Returns:
the modified input stream


Member Data Documentation

int DateTime::mm [private]

the month of the year

int DateTime::dd [private]

the day of the month

int DateTime::yy [private]

the year

int DateTime::h [private]

the hour of the day

int DateTime::m [private]

the minute of the hour

string DateTime::period [private]

the period of the day


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

Generated on Wed Jan 20 09:39:02 2010 by  doxygen 1.5.5