An Efficient Mayan Date Algorithm
Analysis of a Simple Algorithm for Calculating Mayan Dates
Introduction
The Mayan (Meso-American) Long Count Calendar is a fascinating calendar system used by several Meso-American civilizations, before the colonization of the Americas by Europeans and subsequent introduction of the more popular and much simpler Gregorian calendar.
Features that make this calendar so interesting include the fact that it uses modified base-20 and base-18 number systems and that it has positions that can count up to 1.2 billion years (!!) which gives some clues as to the eternal nature in which the creators of this calendar system were able to think and operate within.
While several algorithms and implementations thereof do exist for calculating Mayan from Gregorian dates and vice-versa, none of them had the simplicity and efficiency which I was looking for while prototyping a calendar application for research purposes. Therefore, I chose to design one from scratch (the Dart source project is available here on GitHub).
Let’s take a look at my implementation of this algorithm in Dart:
The MayaLongDate
class contains several properties for managing the date conversion in addition to a standard constructor and toString
override for output in the conventional Mayan x.x.x.x.x
format.
The moduli
property holds the number of days per date position which is used to calculate the date by dividing down from the number of days since the most recent Baktun period start of 12.21.2012
which is defined as MLC_EPOCH_13_START
as a DateTime
object.
The current date in Mayan format is initialized to an empty structure that begins at Baktun 13 as [ 13, 0, 0, 0, 0 ]
which will be populated upon object instantiation with the number of days calculated for each position.
The MayaLongDate
constructor takes a native DateTime
object and normalizes it to the current year, month, and day to remove any time data associated with the input object. Next, the difference in days is calculated between Baktun 13 start and the current normalized date.
Next, functional programming techniques are used to forward-iterate over the Mayan date structure positions, and for each position the lower-bound value is calculated by dividing the number of days in that position into the current running total number of days. The modulus-equals operator is then used to reduce the total remaining day count by the number of days in the current position, allowing the days
variable to be re-used in the next position to “overflow” the total days through the date structure.
Conclusion
This quick and accurate algorithm avoids numerous pitfalls that may be found within more complex ones. Initializing to the current Baktun and reducing the days into each position allows for a very direct calculation versus choosing an arbitrary synchronization date in the past.