/***********************************************************************
The implementation file for the date class including the
implementation of overloaded insertion and extraction and
comparison operators.
John Dolan April 1, 2003
// Author : John Dolan, edited by Travis Dillon
*************************************************************************/
#include "main.h"
#include "node.h"
#include "bag.h"
#include "date.h"
using namespace std;
Date::Date():day(0),month(0),year(0){ }
Date::Date(int d,int m, int y):day(d),month(m),year(y) { }
ostream& operator <<(ostream& outs, Date d){
outs<<d.month<<'/'<<d.day<<'/'<<d.year;
return outs;
}
istream& operator >>(istream& ins, Date& d){
bool flag = false;
while(!ins.eof() && !isdigit(ins.peek())){
ins.ignore();
if(&ins == &cin) cout<<"Use format: mm/dd/yyyy.\n";
}
ins>>d.month;
if(ins.eof()) return ins;
if(ins.peek() == '/') ins.ignore();
ins>>d.day;
if(ins.eof()) return ins;
if(ins.peek() == '/') ins.ignore();
ins>>d.year;
if(ins.eof()) return ins;
while(d.month < 0 || d.month >12){
cout<<"Invalid month.\nMonth: ";
ins>>d.month;
if(ins.eof()) return ins;
flag = true;
}
while(d.day < 0 || d.day > 31){
cout<<"Please enter a valid day:";
ins>>d.day;
if(ins.eof()) return ins;
flag = true;
}
if(flag) cout<<d<<endl;
return ins;
}
bool operator > (const Date& d1, const Date& d2){
if(d1.year != d2.year)
return (d1.year > d2.year);
else if(d1.month != d2.month)
return(d1.month > d2.month);
else
return (d1.day > d2.day);
}
bool operator < (const Date& d1, const Date& d2){
if(d1.year != d2.year)
return (d1.year < d2.year);
else if(d1.month != d2.month)
return(d1.month < d2.month);
else
return (d1.day < d2.day);
}
bool operator == (const Date& d1, const Date& d2){
return(d1.year == d2.year && d1.month == d2.month &&
d1.day == d2.day);
}
bool operator != (const Date& d1, const Date& d2){
return(!(d1.year == d2.year && d1.month == d2.month &&
d1.day == d2.day));
}