Click here to Skip to main content
15,893,588 members
Articles / Programming Languages / C#

Maya Calender Calculator

Rate me:
Please Sign up or sign in to vote.
4.33/5 (4 votes)
23 Jun 2011CPOL3 min read 33.4K   937   12   4
Calculator to convert dates in Maya calendar (long counter) to Gregorian date and vice versa
Sample Image

Introduction

The program is a calculator to convert dates of Maya “long counter” calendar to Gregorian calendar.

Maya long counter calendar was used by ancient Maya culture development in Mesoamerica before the arrival of Columbus 1492. Maya's culture has taken unusual interest because of supposed prophesies about the end of world in 2012 related to the end of the round of Maya long counter calendar. This calculator maybe helps to better understand these matters. You can find a lot of information about Maya on the internet.

Gregorian calendar is our actual calendar in use expressed in year, month and days.

Background

The Mesoamerican Long Count calendar is a non-repeating, vigesimal (base-20) and base-18 calendar used by several Pre-Columbian Mesoamerican cultures, most notably the Maya. For this reason, it is sometimes known as the Maya (or Mayan) Long Count calendar.

Using a modified vigesimal tally, the Long Count calendar identifies a day by counting the number of days passed since a mythical creation date that corresponds to August 11, 3114 BCE in the Gregorian calendar.

Maya long counter is expressed in Baktun, Katun, Tun, Uinal & Kin number which program can convert to a decimal number equivalent to number of days elapsed since initial value.

In order to convert at Gregorian calendar is a little more complicated because Gregorian uses 3 values, year, month & day, and needs to take care of leap years.

The way to help in this conversion is by using Julian Day (JD. This is a calendar not commonly used by normal people, but well known by astronomers and geologists. JD is also (like Maya long counter) a continuous counter of days since January 1st 4113 BC.

Long counter and JD are values of number of days, so to convert between them, we need to know what is the value in JD when the long counter starts. This value is known as “Maya Correlation” and has been a discussion theme for Maya researchers. The value more accepted is called “Goodman Martinez Thompson” of GMT correlation and its value is JD 584.283 equivalent to August 11, 3114 BC in Gregorian calendar (proleptic).

Known correlation then the date in JD will be the long counter value plus the correlation. With date in JD then we convert JD to Gregorian data using some algorithms already known.

To convert JD to Gregorian and vice versa, the program uses the algorithm token from Wikipedia and is implemented in C# code.

Using the Code

The core of the program is a number of routines to implement algorithms to convert between different calendars:

  • Maya2Gregorian
  • Julian2Gregorian
  • JulianDay2JuliaDate
  • Gregorian2JulianDay
  • Gregorian2Maya

Other routines implement inputs and show results.

One example is routine Julian2Gregorian to convert a number of days according to Julian days (JD) to a date according to Gregorian form (years, month, day and day of the week).

The algorithm requires use of mathematic operation mod (module) that can be implemented by C# method Math.DivRem. The method executes quotient between two integers and also calculates the remainder so remainder is the same thing as the module.

Almost all operations use integers of 32 bits. Despite comments about advanced mathematics used by Maya, only operation with integers is enough.

C#
public void Julian2Gregorian(int JD, out int Y, out int M, out int D, out int WD)
{
	/*---------------------------------------------------------------------------------
	* Convert a Julian Day (JD) to Gregorian calendare
	* Information from Wikipedia http://en.wikipedia.org/wiki/Julian_day
	* algorithm converted to C#
	
	* Let J = JD + 0.5: (note: this shifts the epoch back by one half day,
	*                      to start it at 00:00UTC, instead of 12:00 UTC);
	* let j = J + 32044; (note: this shifts the epoch back to astronomical year -4800
	*                      instead of the start of the Christian era in year AD 1 of
	*                      the proleptic Gregorian calendar).
	* let g = j div 146097; let dg = j mod 146097;
	* let c = (dg div 36524 + 1) × 3 div 4; let dc = dg ? c × 36524;
	* let b = dc div 1461; let db = dc mod 1461;
	* let a = (db div 365 + 1) × 3 div 4; let da = db ? a × 365;
	* let y = g × 400 + c × 100 + b × 4 + a; (note: this is the integer number of full
	*                      years elapsed since March 1, 4801 BC at 00:00 UTC);
	* let m = (da × 5 + 308) div 153 ? 2; (note: this is the integer number of full
	*                      months elapsed since the last March 1 at 00:00 UTC);
	* let d = da ? (m + 4) × 153 div 5 + 122; (note: this is the number of days elapsed
	*                      since day 1 of the month at 00:00 UTC, 
				including fractions of one day);

	* let Y = y ? 4800 + (m + 2) div 12; let M = (m + 2) mod 12 + 1; let D = d + 1;
	-----------------------------------------------------------------------------------*/
	
	int j, g, c, b, a, y, m, d;
	int dg, dc, db, da;
	
	j = (int)JD + 32044;
	g = Math.DivRem(j, 146097, out dg);
	c = (dg / 36524 + 1) * 3 / 4;
	dc = dg - (c * 36524);
	b = Math.DivRem(dc, 1461, out db);
	a = (db / 365 + 1) * 3 / 4;
	da = db - (a * 365);
	y = g * 400 + c * 100 + b * 4 + a;
	m = (da * 5 + 308) / 153 - 2;
	d = da - (m + 4) * 153 / 5 + 122;
	Y = y - 4800 + Math.DivRem((m + 2), 12, out M);
	M += 1;
	D = d + 1;
	
	Math.DivRem((int)JD, 7, out WD);
}

History

  • June 22, 2011 - First issue

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Colombia Colombia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiongegorian to mayan Pin
fygy4-Feb-12 14:06
fygy4-Feb-12 14:06 
AnswerRe: gegorian to mayan Pin
eugeniothompson6-Feb-12 3:27
eugeniothompson6-Feb-12 3:27 
GeneralI'm scared Pin
thatraja23-Jun-11 18:54
professionalthatraja23-Jun-11 18:54 
QuestionFun Pin
Olivier_Giulieri23-Jun-11 14:34
Olivier_Giulieri23-Jun-11 14:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.