I have a function that needs to calculate yesterday's, today's and tomorrow's date. I use localtime to get today's date. I add 1 to tm_mday in order to get tomorrow's date. The issue is if the current date is 3/31, it will become 3/32 if I add 1 to tm_mday. Is there any date package in C++ that handles carry over into next month or will I need to write logic to do this?
string get_local_date(const string &s) {
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime(&rawtime);
if (s == "tomorrow") {
timeinfo->tm_mday += 3; // day becomes 3/32
}
if (s == "yesterday") {
timeinfo->tm_mday -= 1;
}
char buffer[80];
strftime(buffer,80,"%04Y-%m-%d",timeinfo);
string str(buffer);
return str;
}