Pi Day is an annual celebration of the mathematical constant $$\pi$$ (pi). It is observed on March 14 (3/14 in the month/day date format) since 3, 1, and 4 are the first three significant digits of π. On March 12, 2009, the U.S. House of Representatives passed a non-binding resolution (HRES 2241), recognizing March 14, 2009 as National Pi Day. For Pi Day 2010, Google presented a Google Doodle2 celebrating the holiday, with the word Google laid over images of circles and pi symbols.

pi pie
Pi pie ofwel Pi-taart, gebakken aan de Technische Universiteit Delft in 2008.

Pi Day has been observed in many ways, including eating pie, throwing pies and discussing the significance of the number $$\pi$$, due to a pun based on the words "pi" and "pie" being homophones in English, as well as pies tending to be round, and thus related to $$\pi$$.

Assignment

In countries that use the day/month date format, Pi Day should be celebrated on April 31. However, the month April only has 30 days. Therefore, we have invented a new calendar where it is allowed to continue enumerating the days at the end of the month. In this system, April 31 would be just a synonym for May 1.

Your task is to implement a function rollover_date that has three optional parameters: day, month and year. These parameters each take an integer (int) that respectively indicates the day, the month and the year in our new calendar system, where it is allowed to continue enumerating the days at the end of the month. The default values for these parameters are respectively the current day, the current month and the current year. The function must return the date (datetime.date) that corresponds to the given date in the regular calendar.

This way, the function call rollover_date(43, 15, 2016) reads as the 43rd day of the 15th month of the year 2016. To convert this date to the regular calendar, we first roll over the month to the next year, so we end up with March, the third month of the year 2017. Now, since March only has 31 days, we roll over the extra days to April, so we finally end up with April 12, 2017. Dates that are also valid in the regular calendar, remain unchanged by this procedure. Rolling over dates should take leap years into consideration.

Example

>>> rollover_date(month=4, day=31)
datetime.date(2024, 5, 1)
>>> rollover_date(year=2016, month=15, day=43)
datetime.date(2017, 4, 12)
>>> rollover_date(year=2016, month=3, day=16)
datetime.date(2016, 3, 16)
>>> rollover_date(year=2016, month=12, day=64)
datetime.date(2017, 2, 2)
>>> rollover_date(year=2016, month=19, day=99)
datetime.date(2017, 10, 7)
>>> rollover_date(year=2016, month=1, day=99999)
datetime.date(2289, 10, 14)
>>> rollover_date(year=2016, month=9999, day=10)
datetime.date(2849, 3, 10)