Was just reading about it in “Celestial Calculations” by J. L. Lawrence. See Chapter 3.

Also, C++11 has good support for dates/times, see https://stackoverflow.com/questions/14218894/number-of-days-between-two-dates-c

]]>if ((day_of_month(start_date) == 31) && (day_of_month(end_date) == 30)) day_of_month(start_date) = 30;

After that the original code should be fine.

]]>1 month 1 day, 1 month, or 4 weeks 1 day? Answer: depends on the month.

Honestly, for the initial example, I think the “correct” solution is don’t use uints and let the answer be “5 months minus a day”.

]]>The solve the problem the easiest, is to first add day, do your calculation, then subtract a day.

I suggest the same approach for the calculator, it will feel the most “natural” to humans

So, add a day to start and end, calculate the difference (no bug fix required)