Is there a way to add months and their respective days in my + operator?
Date operator + (Date const& dt, Month const& m)
{
jdn_type months_to_add = m.month_;
jdn_type days_to_add;
gregorian_type g = dt.gregorian();
long d = std::get<1>(g);
if(d == 1){
days_to_add = 31*m.month_;
}
else if(d == 2){
days_to_add = 28*m.month_;
}
else if(d == 3){
days_to_add = 31*m.month_;
}
else if(d == 4){
days_to_add = 30*m.month_;
}
else if(d == 5){
days_to_add = 31*m.month_;
}
else if(d == 6){
days_to_add = 30*m.month_;
}
else if(d == 7){
days_to_add = 31*m.month_;
}
else if(d == 8){
days_to_add = 31*m.month_;
}
else if(d == 9){
days_to_add = 30*m.month_;
}
else if(d == 10){
days_to_add = 31*m.month_;
}
else if(d == 11){
days_to_add = (30*m.month_)+4;
}
else if(d == 12){
days_to_add = 365;
}
return Date(dt.jdn() + days_to_add);
}
//** AND MY BOOST TEST FOR THAT **//
BOOST_AUTO_TEST_CASE(date_month_test)
{
Date theDate(2010,Date::JAN, 24);
//addition for month test
Date date1(2010,Date::MAR, 24);
Month m(2);
Date newDate = theDate + m;
BOOST_CHECK(newDate == date1);
}