Sunday, August 26, 2012

Oddness with the Maya Calendar

So I've been reading up a LOT on the Maya* calendar over the past few months. There are two different calendrical systems - the Long Count (which is what we hear about when people talk about the end of the world in 2012). The current date in Long Count (as of this post) is There's another calendar is called the Sacred Round and uses what are called Tzolk'in and Haab dates. This calendar was more religious in nature and had a full cycle of about 52 years. When doing calculations for Long Count or Maya calendars it's common to include both the Long Count and the Sacred Round dates.
One thing that seems clear is the basic calculations to get the Sacred Round dates. The Wikipedia article describes pretty clearly the arithmetic required to derive these. The regular Sacred Round cycle is 360 days and there are 5 Wayeb days (that were considered unlucky) to make the calendar 365 days long. Close to the 365.2422 days our tropical calendar is, but it means that the Sacred Round shifts one day forward compared to the tropical year every 4 years.
One problem is that I would like for my application to work for dates all the way back to 9999 BCE (and forward to 9999 AD/CE). Most calculations are done using Julian days as a baseline, but the Julian dates start in 4730 BCE, a little later than my 9999 BCE desire. What's a developer to do? Well, one option is to try to address the negative values that come from going before the start of the Julian dating scheme, which is what I initially thought of doing. Then I realized that since there is a higher-order cycle above the currently accepted five values, I could add what's called a piktun worth of days to the count, in essence moving back the Julian calendar about seven thousand years. I did this and it worked great for the Long Count calculations - I just subtracted out a piktun if it was past the beginning of this cycle or not - it all worked out. The Sacred Round, however, was a different story.
The reason is that the Sacred Round starts at specific values for tzolk'in and haab. Moving back a whole piktun, though, means I needed to recalculate the tzolk'in and haab values. I figured out what the new offsets were and after resolving some oddness with displaying the correct glyph for the tzolk'in and haab I seem to have gotten everything working.
The only things I have left to do to get this thing out the door is finish the polish for iPhone and get the iPad version looking reasonable. All of the testing I've done to date is solid. I still have a few things left to validate, but I actually have a high confidence that it will work pretty well. Then two versions - one free and ad-supported and one for $0.99. Then I'll have broken my 3.5 year drought of getting apps into the App Store. Yay?

* You'll note that I'm not using "Mayan" anymore. I learned that Mayanists (scholars who study the Maya history) use "Mayan" for linguistic elements (the language) but use "Maya" as an adjective for "things that are from the Maya culture"). I will bow to their superior expertise and understanding in this particular matter.