There is simply no algorithm that accounts for their behaviour all the time. The best you can do is have one that works most of the time, and then have a table of exceptions (which has to be locale based).
For example, what date is 15330 days after February 30(!) 1712 in Sweden?[1]
In November 1699, Sweden decided that, rather than adopting the Gregorian calendar outright, it would gradually approach it over a 40-year period. The plan was to skip all leap days in the period 1700 to 1740.
Great.. except:
In accordance with the plan, February 29 was omitted in 1700, but due to the Great Northern War no further reductions were made in the following years.
Oops. Oh well:
In January 1711, King Charles XII declared that Sweden would abandon the calendar, which was not in use by any other nation and had not achieved its objective, in favour of a return to the older Julian calendar. An extra day was added to February in the leap year of 1712, thus giving it a unique 30-day length
But the Julian calendar sucks[2], so:
In 1753, one year later than England and its colonies, Sweden introduced the Gregorian calendar, whereby the leap of 11 days was accomplished in one step, with February 17 being followed by March 1
Once you start doing date work you'll find these crazy cases all the time. Try and tell me today's date on Mount Athos...
[1] https://en.wikipedia.org/wiki/Swedish_calendar#Solar_calenda...
[2] https://en.wikipedia.org/wiki/Julian_calendar
[3] https://en.wikipedia.org/wiki/Mount_Athos#Date_and_time_reck...