Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Date.h"
- Date::Date()
- {
- dateDelimeter='/';
- timeDelimeter=':';
- resDate="";
- resTime="";
- resDay=0;
- resMonth=0;
- resYear=0;
- resMinute=0;
- resHour=0;
- }
- Date::Date(unsigned int day, unsigned int month, unsigned int year, unsigned int minute, unsigned int hour)
- {
- setResDate(day, month, year);
- setResTime(minute, hour, day);// 45 22 20
- }
- Date::Date(Date &obj)
- {
- dateDelimeter='/';
- timeDelimeter=':';
- resDate=obj.getResDate();
- resTime=obj.getResTime();
- resDay=obj.getResDay();
- resMonth=obj.getResMonth();
- resYear=obj.getResYear();
- resMinute=obj.getResMinute();
- resHour=obj.getResHour();
- }
- bool Date::setResDate(unsigned int day, unsigned int month, unsigned int year)
- {
- if(verifyResDate(day, month, year)==true)
- {
- resDay=day;
- resMonth=month;
- resYear=year;
- if (day<10)
- {
- resDate="0"+to_string(resDay);
- }
- else
- {
- resDate=to_string(resDay);
- }
- if (month<10)
- {
- resDate+="/0"+to_string(resMonth);
- }
- else
- {
- resDate+="/"+to_string(resMonth);
- }
- resDate+="/"+to_string(resYear);
- return true;
- }
- else
- {
- cout<<"\nDate could be assigned since it is not withing valid range.\n";
- return false;
- }
- }
- bool Date::setResTime(unsigned int minute,unsigned int hour, unsigned int day)// 45 22 20
- {
- if(verifyResTime(minute, hour, day)==true)
- {
- resMinute=minute;
- resHour=hour;
- resTime=to_string(resHour)+":"+to_string(resMinute);
- return true;
- }
- else
- {
- cout<<"\nTime could be assigned since it is not withing valid range.\n";
- return false;
- }
- }
- bool Date::setResTime(string val)
- {
- //checkTimeFormat(val);
- if(checkTimeFormat(val)!=false && verifyResTime(val)!=false)
- {
- cout<<"did i make it"<<endl;
- resTime=val;
- system("PAUSE");
- return true;
- }
- else
- {
- cout<<"\nTime could be assigned since it is not withing valid range.\n";
- return false;
- }
- }
- void Date::setResDirect(string val)
- {
- resTime=val;
- parseResTime();
- }
- bool Date::setResDate(string val)
- {
- if(checkDateFormat(val)!=false && verifyResDate(val)!=false)
- {
- resDate=val;
- parseResDate();
- return true;
- }
- else
- {
- cout<<"\nDate could not be assigned, as it is not within valid range\n";
- return false;
- }
- }
- bool Date::verifyResDate()
- {
- time_t curtime=time(NULL);//uses the time_t standard data type to crate the object curt time
- struct tm *tmdata=localtime(&curtime);
- unsigned int y=tmdata->tm_year+1900;//sets y to the years since the year 1900 + 1900, yielding current year.
- unsigned int m=tmdata->tm_mon+1;//sets month to current month, however tm_mon is from 0 to 11, so a one is added to get the proper 12
- unsigned int d=tmdata->tm_mday;//returns day of the month
- return repetativeComparison(resDay, resMonth, resYear, d, m , y);
- }
- bool Date::verifyResDate(unsigned int day,unsigned int month,unsigned int year)
- {
- time_t curtime=time(NULL);//uses the time_t standard data type to crate the object curt time
- struct tm *tmdata=localtime(&curtime);
- int y=tmdata->tm_year+1900;//sets y to the years since the year 1900 + 1900, yielding current year.
- int m=tmdata->tm_mon+1;//sets month to current month, however tm_mon is from 0 to 11, so a one is added to get the proper 12
- int d=tmdata->tm_mday;
- return repetativeComparison(day, month, year, d, m , y);
- }
- bool Date::verifyResDate(string val)
- {
- string sday=val.substr(0, val.find(dateDelimeter));
- val=val.erase(0, val.find(dateDelimeter)+1);
- string smonth=val.substr(0, val.find(dateDelimeter));
- val=val.erase(0, val.find(dateDelimeter)+1);
- string syear=val;
- unsigned int month=atoi(smonth.c_str());
- unsigned int day=atoi(sday.c_str());
- unsigned int year=atoi(syear.c_str());
- time_t curtime=time(NULL);//uses the time_t standard data type to crate the object curt time
- struct tm *tmdata=localtime(&curtime);
- int y=tmdata->tm_year+1900;//sets y to the years since the year 1900 + 1900, yielding current year.
- int m=tmdata->tm_mon+1;//sets month to current month, however tm_mon is from 0 to 11, so a one is added to get the proper 12
- int d=tmdata->tm_mday;
- return repetativeComparison( day, month, year, d, m , y);
- }
- //verify res date
- //fix verify res time here
- bool Date::verifyResTime()
- {
- time_t curtime=time(NULL);//uses the time_t standard data type to crate the object curt time
- struct tm *tmdata=localtime(&curtime);
- unsigned short m=tmdata->tm_min;
- unsigned short h=tmdata->tm_hour;
- unsigned short d=tmdata->tm_mday;
- if(dateGreater==true)
- {
- if(resHour>24 || resHour<0 || resMinute>59 || resMinute<0)
- {
- return false;
- }
- else{return true;}
- }
- else if(resDay==d)
- {
- if(resHour>24 || resHour<0 || resMinute>59 || resMinute<0)
- {
- return false;
- }
- if(resHour>h)
- {
- return true;
- }
- else if(resHour==h && resMinute>=m)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- bool Date::verifyResTime(unsigned int minute, unsigned int hour, unsigned int day) //45 22 20
- {
- time_t curtime=time(NULL);//uses the time_t standard data type to crate the object curt time
- struct tm *tmdata=localtime(&curtime);
- unsigned short m=tmdata->tm_min;
- unsigned short h=tmdata->tm_hour;
- unsigned short d=tmdata->tm_mday; //8
- if(dateGreater==true||yearGreater==true)
- {
- if(hour>23 || hour<0 || minute>59 || minute<0)
- {
- return false;
- }
- else{return true;}
- }
- else
- {
- if(day==d)
- {
- if(hour>23 || hour<0 || minute>59 || minute<0)
- {
- return false;
- }
- if(hour>h)
- {
- return true;
- }
- else if(hour==h && minute>=m)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else{
- return false;
- }
- }
- }
- bool Date::verifyResTime(string val)
- {
- time_t curtime=time(NULL);//uses the time_t standard data type to crate the object curt time
- struct tm *tmdata=localtime(&curtime);
- unsigned short mm=tmdata->tm_min;
- unsigned short hh=tmdata->tm_hour;
- unsigned short dd=tmdata->tm_mday;
- unsigned short month=tmdata->tm_mon+1;
- unsigned short year=tmdata->tm_year+1900;
- cout<<val.at(0)<<endl;
- cout<<val.find(timeDelimeter)+1;
- string sun=val.substr(0,val.find(timeDelimeter));
- unsigned short hour=atoi(sun.c_str());
- sun=val.erase(0,(val.find(timeDelimeter))+1);
- unsigned short minute = atoi(sun.c_str());
- cout<<'\n'<<hour<<" : "<<minute<<endl;
- system("PAUSE");
- if(hour >23 || hour < 0 || minute > 59 || minute < 0)
- {
- return false;
- system("PAUSE");
- }
- else if(resYear>year || (resYear==year && resMonth>month) || (resYear==year && resMonth==month && resDay>dd))
- {
- return true;
- system("PAUSE");
- }
- else if(resDay==dd)
- {
- if(hour>hh)
- {
- return true;
- }
- else if(hour==hh && minute>=mm)
- {
- return true;
- }
- else
- {
- return false;
- }
- system("PAUSE");
- }
- else
- {
- return false;
- }
- system("PAUSE");
- }
- void Date::parseResDate()
- {
- unsigned short count=0;
- unsigned short pos=0;
- string token;
- string rd=resDate;
- while((pos=rd.find(dateDelimeter)!=string::npos))
- {
- token=rd.substr(0, pos+1);
- rd=rd.erase(0,pos+2);
- if(count==0)
- {
- resDay=atoi(token.c_str());
- }
- else if(count==1)
- {
- resMonth=atoi(token.c_str());
- }
- if(count==1)
- {
- resYear=atoi(rd.c_str());
- }
- count++;
- }
- }
- void Date::parseResTime()
- {
- string rt;
- string token;
- unsigned short pos=0;
- unsigned short count=0;
- rt=resTime;
- while((pos=rt.find(timeDelimeter))!=string::npos)
- {
- token=rt.substr(0, pos+1);
- rt=rt.erase(0, pos+1);
- if(count==0)
- {
- resHour=atoi(token.c_str());
- }
- else
- {
- resMinute=atoi(token.c_str());
- }
- verifyResTime();
- count++;
- }
- }
- bool Date::checkDateFormat()
- {
- if(resDate.length()>=8 && resDate.length()>=10)
- {
- string sub=resDate.substr(0, resDate.find(dateDelimeter)+1);
- if(resDate.find(dateDelimeter)!=2 && resDate.find(dateDelimeter)!=3 && sub.find(dateDelimeter)!=2 && sub.find(dateDelimeter)!=3)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else{return false;}
- }
- bool Date::checkTimeFormat()
- {
- if(resTime.length()<=5 && resTime.length()>=4 && (resTime.find(timeDelimeter)==2||resTime.find(timeDelimeter)==3))
- {
- return true;
- }
- else{return false;}
- }
- bool Date::checkDateFormat(string val)
- {
- if(val.length()>=8 && val.length()<=10)
- {
- string sub=val.substr(val.find(dateDelimeter)+1, (val.length()-(val.find(dateDelimeter)+1)));
- if((val.find(dateDelimeter)==2 || val.find(dateDelimeter)==3) && (sub.find(dateDelimeter)==1 || sub.find(dateDelimeter)==2))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else{return false;}
- }
- bool Date::checkTimeFormat(string val)
- {
- if(val.length()<=5 && val.length()>=4 && val.find(timeDelimeter))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- unsigned int Date::getResDay() { return resDay; }
- unsigned int Date::getResMonth() { return resMonth; }
- unsigned int Date::getResYear() { return resYear; }
- unsigned int Date::getResHour() { return resHour; }
- unsigned int Date::getResMinute() { return resMinute; }
- string Date::getResDate() { return resDate; }
- string Date::getResTime() { return resTime; }
- string Date::getResTime12()
- {
- if(resHour>12)
- {
- string resHour12=to_string((resHour-12));
- string newTime=resHour12+":"+to_string(resMinute)+" PM";
- return newTime;
- }
- else
- {
- return resTime+" AM";
- }
- }
- bool Date::repetativeComparison(int day, int month, int year, int d, int m , int y)
- {
- if(year>y && year<=y+1)//RESERVATIONS CAN BE MADE ATMOST ONE YEAR IN ADVANCE
- {
- yearGreater=true;
- dateGreater=true;
- return true;
- }
- else if(y>year)
- {
- yearGreater=false;
- return false;
- }
- else
- {
- yearGreater=false;
- }
- if(year==y && month<m)
- {
- return false;
- }
- else if(year==y && month==m && day<d)
- {
- return false;
- }
- if(month>12 || month<1)
- {
- return false;
- }
- if (yearGreater==true)//THIS IS TO ENSURE THAT IF THE DESIRED YEAR IS GREATER THAN THE SELECTED YEAR, THEY CAN PICK ANY DATE
- {
- if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&& (day<=31&&day>=1) )//These conditions are based on the amount of days in a specific month
- {
- return true;
- }
- else if((month==2)&&(day<=28&&day>=1))
- {
- return true;
- }
- else if((year%4==0)&&(month==2)&&(day<=29 && day>=1))
- {
- return true;
- }//fix the thing here
- else if((month==4||month==6||month==9||month==11)&&(day<=30&&day>=1))
- {
- return true;
- }
- else{return false;}
- }
- else{
- if(year==y && month>=m)
- {
- if(month>m || (month==m && day>d) || (month==m && day==d))
- {
- dateGreater=true;
- return true;
- }
- else
- {
- dateGreater=false;
- return true;
- }
- if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&& (day<=31&&day>=1) )//These conditions are based on the amount of days in a specific month
- {
- return true;
- }
- else if((month==2)&&(day<=28&&day>=1))
- {
- return true;
- }
- else if((year%4==0)&&(month==2)&&(day<=29 && day>=1))
- {
- return true;
- }
- else if((month==4||month==6||month==9||month==11)&&(day<=30&&day>=1))
- {
- return true;
- }
- else{return false;}
- }
- else
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement