/*	Implementation of a DateClass class that stores month, day, and year.
	Two free functions are included: operator << and operator >>             */
	
using namespace std;	// October 5, 2001

DateClass::DateClass()
	: Month(0), Day(0), Year(0)
{
}
//--------------------------------------------------------------------------------
DateClass::DateClass(int MonthArg, int DayArg, int YearArg)
	: Month(MonthArg), Day(DayArg), Year(YearArg)
{
}
//--------------------------------------------------------------------------------
bool DateClass::Read(istream & InFile)
/*	Reads a date from InFile. Input is assumed to be in mm/dd/yy form.
	true returned if date not 0/0/0.
	Post: String read from InFile and parsed into Month, Day, and Year.
	true returned if date not 0/0/0. false returned otherwise.                    */
{
	lvpstring S, MonthStr, DayStr, YearStr;
	getline(InFile,S);

	MonthStr = S.substr(0,S.find('/'));
	S = S.substr(S.find('/')+1,S.length()-S.find('/')-1);
	DayStr = S.substr(0,S.find('/'));
	YearStr = S.substr(S.find('/')+1,S.length()-S.find('/')-1);

	Month = atoi(MonthStr.c_str());
	Day = atoi(DayStr.c_str());
	Year = atoi(YearStr.c_str());

	return ((Month!=0) && (Day!=0) && (Year!=0));
}
//--------------------------------------------------------------------------------
void DateClass::SetDate(int MonthArg, int DayArg, int YearArg)
{
	Month = MonthArg;
	Day = DayArg;
	Year = YearArg;
}
//--------------------------------------------------------------------------------
void DateClass::Write(ostream & OutFile) const
/*	Writes D to the output stream
	Post: D written to OutFile                */
{
	OutFile.width(2); OutFile << Month << '/';
	OutFile.width(2); OutFile << Day << '/';
	OutFile.width(2); OutFile << Year;
}
//--------------------------------------------------------------------------------
bool DateClass::operator <(const DateClass Date2) const
{
	if (Year < Date2.Year)
		return (true);
	else if (Year > Date2.Year)
		return (false);
	else if (Month < Date2.Month)
		return (true);
	else if (Month > Date2.Month)
		return (false);
	else
		return (Day < Date2.Day);
}
//--------------------------------------------------------------------------------
bool DateClass::operator > (const DateClass Date2) const
{
	return (!(operator==(Date2)) && !(operator<(Date2)));
}
//--------------------------------------------------------------------------------
bool DateClass::operator == (const DateClass Date2) const
{
	return ((Day == Date2.Day) && (Month == Date2.Month) &&
		(Year == Date2.Year));
}
//--------------------------------------------------------------------------------
bool DateClass::operator != (const DateClass Date2) const
{
	return !(operator==(Date2));
}
//--------------------------------------------------------------------------------
bool DateClass::operator >= (const DateClass Date2) const
{
	return ((operator==(Date2)) || (operator>(Date2)));
}
//--------------------------------------------------------------------------------
bool DateClass::operator <= (const DateClass Date2) const
{
	return ((operator==(Date2)) || (operator<(Date2)));
}


//--------------------------------------------------------------------------------
ostream& operator << (ostream & OutFile, const DateClass &D)
{
	D.Write(OutFile);
	return (OutFile);
}
//--------------------------------------------------------------------------------
istream & operator >>(istream &InFile, DateClass &D)
/*	Reads from InFile to D
	Post: D is read from Infile */
{
	D.Read(InFile);
	return (InFile);
}


