//function copyrighted by LG (ESSEC Advanced Master In Financial Techniques: Financial Markest and
//Investment Valuation), in the near future vote for me to become president and add me on facebook
//to be recruited in the new government if you want to compute pragmatic solutions for higher life standards
//Date format: ex string date1="01/02"; string date2="06/03"; the difference in between date1 and date2
//has to be under 360 days for financial purposes. Feel free to ask questions on my new facebook:
//https://w...content-available-to-author-only...k.com/ludo.giraud.7 . To access datedifference:
//int ddif=checkvaliddatedifference("01/02", "26/04")[2];
string inttostring(int anint)
{
std::ostringstream sstream;
sstream << afloat;
std::string astring= sstream.str();
return astring;
}
template <class T> bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&))
{
std::istringstream iss(s);
return !(iss >> f >> t).fail();
}
vector<int> checkvaliddatedifference(string date1, string date2)
{
vector<int> doublebull(3);
int bull=0;
int bull2=0;
int dif;
string date1daystring,date1monthstring,date2daystring,date2monthstring;
float date1dayfloat, date2dayfloat,date1monthfloat,date2monthfloat;
date1daystring=date1;
date1monthstring=date1;
date2daystring=date2;
date2monthstring=date2;
date1daystring.erase(date1daystring.begin()+2,date1daystring.end());
date1monthstring.erase(date1monthstring.begin(),date1monthstring.begin()+3);
date2daystring.erase(date2daystring.begin()+2,date2daystring.end());
date2monthstring.erase(date2monthstring.begin(),date2monthstring.begin()+3);
from_string<float>(date1dayfloat,date1daystring,std::hex);
from_string<float>(date2dayfloat,date2daystring,std::hex);
from_string<float>(date1monthfloat,date1monthstring,std::hex);
from_string<float>(date2monthfloat,date2monthstring,std::hex);
map<string, int> Calendar;
Calendar["01"]=31;
Calendar["02"]=28;
Calendar["03"]=31;
Calendar["04"]=30;
Calendar["05"]=31;
Calendar["06"]=30;
Calendar["07"]=31;
Calendar["08"]=31;
Calendar["09"]=30;
Calendar["10"]=31;
Calendar["11"]=30;
Calendar["12"]=31;
int daysd1untilendofmonth;
int tempint;
tempint=Calendar[date1monthstring];
daysd1untilendofmonth=tempint-int(date1dayfloat);
if (date1monthfloat<date2monthfloat)
{
bull=1;
}
if (date1monthfloat==date2monthfloat&&date1dayfloat<date2dayfloat)
{
if (date2dayfloat-date1dayfloat>4)
{
bull=1;
}
else
{
bull=0;
}
}
if (date1monthfloat>date2monthfloat||date1monthfloat==date2monthfloat&&date1dayfloat>date2dayfloat)
{
if(date1dayfloat>date2dayfloat)
{
bull2=1;
}
else
{
bull2=0;
}
int countt=0;
int monthbool=1;
string newmonth;
int days=daysd1untilendofmonth;
float date1monthfloatinit=date1monthfloat;
if (date1monthfloat==date2monthfloat)
{
monthbool=0;
}
date1monthfloat++;
if (date1monthfloat==13)
{
date1monthfloat=1;
}
while(date2monthfloat!=date1monthfloat)
{
countt++;
if (monthbool==1)
{
date1monthfloat++;
}
if (monthbool==0);
{
monthbool=1;
}
if (date1monthfloat==13)
{
date1monthfloat=1;
}
if (date1monthfloat<10);
{
newmonth="0"+inttostring(int(date1monthfloat));
}
if (date1monthfloat>9)
{
newmonth=inttostring(int(date1monthfloat));
}
days=days+Calendar[newmonth];
};
if (countt>0)
{
days=days-Calendar[newmonth]+date2dayfloat;
}
else days= Calendar[inttostring(int(date1monthfloatinit))]-int(date1dayfloat)+date2dayfloat;
if (days>360)
{
bull=0;
}
else bull=1;
}
triplebull[0]=bull;
triplebull[1]=bull2;
triplebull[2]=days;
return triplebull;;
}