Most calendar systems work with cyclic time periods to represent dates that identify specific days in the calendar. Our Gregorian calendar, for example, uses days, months and years as time periods.
The long count of the Maya calendar, on the other hand, works with five time periods instead of three. Every day is called a kin, and every time period of 20 kin is a uinal. 18 uinals are called a tun, 20 tun a katun, and 20 katun are a baktun. There is no upper limit to the number of baktun, just as there is no upper limit to the number of years in the Gregorian calendar.
In addition, time periods of a date in the Gregorian calendar are represented from short to long (days, months, years), whereas those of the Maya calendar go from long to short (baktuns, katuns, tuns, uinals, kins). Finally, the Gregorian calendar numbers values for the time periods starting from 1, whereas the Maya calendar counts from 0.
Express a day represented as a date in the Gregorian calendar as its corresponding date in the Maya calendar. For example, the Gregorian date 12/12/2012 corresponds with the date 12.19.19.17.11 in the Maya calendar. Dates are always represented as a string that lists the individual values for each of the time periods. The individual values are always separated by the same character. Any character can be used as a separator, as long as it is not a digit. The individual values are integers, but they may be represented with a random number of leading zeroes that don't have any further meaning. We only take into account days from the Gregorian date 01/01/1970 onward. You are asked to:
Write a function dmy that takes a date in the Gregorian calendar. The function must return a tuple containing three integers: the day, the month and the year of the given date.
Use the function dmy to write a function expired that takes a date in the Gregorian calendar. The function expired must return the number of days that have passed since January 1, 1970 (Gregorian date).
Use the function expired to write a function mayadate. The function mayadate has two parameters: a parameter date that takes a date in the Gregorian calendar, and an optional parameter separator that takes a string containing a single character. The function must return the date in the Maya calendar that corresponds to the given date in the Gregorian calendar. To determine the date in the Maya calendar, you may assume that the date 01/01/1970 in the Gregorian calendar corresponds to the date 12.17.16.7.5 in the Maya calendar. Count the number of days that have passed since this reference date, until you reach the requested date. The individual values for the time periods in the Maya calendar must be represented without leading zeroes, and are separated from one another using the given separator. If no separator was explicitly passed to the function, the function must use the same character used to separate the numbers in the given Gregorian date.
>>> dmy('01/01/1970')
(1, 1, 1970)
>>> dmy('20-7-1988')
(20, 7, 1988)
>>> dmy('00012+00012+02012')
(12, 12, 2012)
>>> dmy('21 12 2012')
(21, 12, 2012)
>>> dmy('26.03.2407')
(26, 3, 2407)
>>> expired('01/01/1970')
0
>>> expired('20-7-1988')
6775
>>> expired('00012+00012+02012')
15686
>>> expired('21 12 2012')
15695
>>> expired('26.03.2407')
159695
>>> mayadate('01/01/1970')
'12/17/16/7/5'
>>> mayadate('20-7-1988',separator='/')
'12/18/15/4/0'
>>> mayadate('00012+00012+02012',separator='-')
'12-19-19-17-11'
>>> mayadate('21 12 2012',separator='+')
'13+0+0+0+0'
>>> mayadate('26.03.2407')
'14.0.0.0.0'