Project 1
Public Member Functions | Private 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)
 
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)
 

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
1.2, 01/08/20

Constructor & Destructor Documentation

◆ DateTime() [1/2]

DateTime::DateTime ( )

Default constructor. Sets a defalt object to "01/01/00 12:00 AM".

◆ DateTime() [2/2]

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.

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

◆ operator!=()

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

◆ operator<()

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

◆ operator==()

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

◆ operator>()

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

◆ setDate()

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

Sets the date portion of this object. Directly 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

◆ setTime()

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

Sets the time porition of this object. Directly 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

◆ toLong()

unsigned long DateTime::toLong ( ) const
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.

Returns
an unsigned long that is equivalent to the date and time

Friends And Related Function Documentation

◆ operator<< [1/2]

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

◆ operator<< [2/2]

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

◆ operator>>

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

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

◆ dd

int DateTime::dd
private

the day of the month

◆ h

int DateTime::h
private

the hour of the day

◆ m

int DateTime::m
private

the minute of the hour

◆ mm

int DateTime::mm
private

the month of the year

◆ period

string DateTime::period
private

the period of the day

◆ yy

int DateTime::yy
private

the year


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