Skip to content

Instantly share code, notes, and snippets.

@vbresan
Created June 21, 2025 05:16
Show Gist options
  • Select an option

  • Save vbresan/44063a6f017c017b6d00ed824105756f to your computer and use it in GitHub Desktop.

Select an option

Save vbresan/44063a6f017c017b6d00ed824105756f to your computer and use it in GitHub Desktop.
Python function that converts a haab date to a tzolkin date (Mayan calendars).
def solve(haab_date: str) -> str:
"""
Converts a haab date to a tzolkin date. See:
https://en.wikipedia.org/wiki/History_of_calendars#Mesoamerica
https://en.wikipedia.org/wiki/Maya_calendar
"""
months = ["pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu"]
parts = haab_date.split()
day = int(parts[0][:-1])
month = months.index(parts[1])
year = int(parts[2])
if year < 0 or year >= 5000:
return ""
day_since = year * 365 + month * 20 + day
out_year = day_since // 260
day_since -= out_year * 260
out_month = day_since % 13 + 1
days = ["imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"]
day = days[day_since % 20]
return f"{out_month} {day} {out_year}"
if __name__ == "__main__":
solve("10. zac 0")
solve("0. pop 0")
solve("10. zac 1995")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment