Package: tzolkin-calendar
tzolkin-calendar - Converter for Maya Tzolk’in DatesThis program converts mayan Tzolk’in dates to Gregorian dates and vice versa.
If you want to know more about the Maya calendar systems, seeLinks.Information about the installation and usage you find atInstallation and UsageMore detailed Documentation can be found atRead the Docsmore badgesTable of Contentstzolkin-calendar - Converter for Maya Tzolk’in DatesLinksInstallation and UsagePrerequisitesInstallationUsageUsing the Command-Line ClientConverting Gregorian Dates to Tzolk’in DatesSearching Tzolk’in DatesPrint all Tzolk’in Dates in a Tzolk’in YearUsing the Jupyter NotebookUsing the Python Module in Your ProgramsImport the ModuleThe Tzolk’in Date ClassTzolkinConvert Gregorian Dates to Tzolk’in DatesSet Tzolk’in DatesSearch Gregorian Dates to a given Tzolk’in DateCalculations using  Tzolk’in DatesMore informationContributingReport Issues (Bugs and Feature Requests)Changing the Documentation and Source CodeGithub Documentation on Collaborating with Issues and Pull RequestsMore InformationLicenseBadgesExternal ChecksStatic Code ChecksTestsLinksSmithsonian Museo Nacional del Indígena Americano:Viviendo El Tiempo MayaWebsite of the Smithsonian National Museum of the American Indian on MayasLiving Maya Time.Online general Maya (not only Tzolk’in) calendar converter:Maya Converter of the Smithsonian NMAIConvertidor Al Calendario Maya Smithsonian NMIAMayan Glyphs and Unicode:Roadmap to the SMPand the PDFUpdated List of Characters for Mayan CodicesInstallation and UsageThere are 3 Jupyter Notebooks online atBinder:Interactive Tzolk’in converter:Command line program:The usage of the module tzolkin-calendar in your code:PrerequisitesYou need Python, at least version 3.8 to be able to use tzolkin-calendar. You can
download it frompython.org.To install the package, you need pip, seeInstalling pip.InstallationInstall the package using pip on a shell or command prompt:python-mpipinstalltzolkin-calendarMore information about using pip you get atpip QuickstartUsageUsing the Command-Line ClientThere is an online interactive Jupyter version:We start the command line client oftzolkin-calendarusingpython -m: beware of the underscore (_)%python-mtzolkin_calendarGregorian "24.03.2021" is "3 Men" as Tzolk’inAs default, if no argument is given, the Tzolk’in date of the current day ('today' ins the 24th of March, 2021) is printed.To get the version oftzolkin_calendar, use the argument--version%python-mtzolkin_calendar--versiontzolkin-calendar 0.9.3The argument--helpdisplays a short usage text, we go through all options in the following parts.%python-mtzolkin_calendar--helpusage: python -m tzolkin_calendar [-h] [--version] [-l LIST_LENGTH]
                                      [-s START_DATE] [-y]
                                      [DATE ...]

    A Tzolk’in date converter and calculator.

    Examples:

    To get the Tzolk’in date of today:

     python -m tzolkin_calendar

    To get the next and last gregorian dates with a Tzolk’in date of '8 Chuwen' you can use either:

     python -m tzolkin_calendar 8 Chuwen
     python -m tzolkin_calendar 8/Chuwen
     python -m tzolkin_calendar 8.Chuwen
     python -m tzolkin_calendar 8-Chuwen
     python -m tzolkin_calendar 8 11
     python -m tzolkin_calendar 8/11
     python -m tzolkin_calendar 8.11
     python -m tzolkin_calendar 8-11

    To get the Tzolk’in date of the 16th april 2016, use one of these date formats:

        python -m tzolkin_calendar 16.04.2016
        python -m tzolkin_calendar 16-04-2016
        python -m tzolkin_calendar 16 04 2016
        python -m tzolkin_calendar 2016.04.16
        python -m tzolkin_calendar 2016-04-16
        python -m tzolkin_calendar 2016/04/16
        python -m tzolkin_calendar 2016 04 16
        python -m tzolkin_calendar 04/16/2016

    positional arguments:
      DATE                  The date to parse and convert. Either a Tzolk’in date or a gregorian date can be given. The default is the date of today.

    optional arguments:
      -h, --help            show this help message and exit
      --version             show program's version number and exit
      -l LIST_LENGTH, --list LIST_LENGTH
                            Display a list of dates with the given Tzolk’in date instead of a single one. The length of the list is LIST_LENGTH.
      -s START_DATE, --start START_DATE
                            The start date to begin the search for the dates with the same Tzolk’in date. The same formatting rules apply as for the main argument DATE.
      -y, --year            Print all dates of a Tzolk’in year.

    See website https://github.com/Release-Candidate/tzolkin_calendar for a detailed description.Converting Gregorian Dates to Tzolk’in DatesTo get the Tzolk’in date of a Gregorian date use the Gregorian date as the main argument totzolkin_calendar.E.g. to get the Tzolk’in date of the 18th of May, 1974, which is "12 Akʼbʼal"%python-mtzolkin_calendar18.05.1974Gregorian "18.05.1974" is "12 Akʼbʼal" as Tzolk’inMany date format conventions are supported, any of these work (and result in the 18th of May, 1974):DD.MM.YYYY - 18.05.1974DD-MM-YYYY - 18-05-1974DD MM YYYY - 18 05 1974YYYY.MM.DD - 1974.05.18YYYY-MM-DD - 1974-05-18YYYY/MM/DD - 1974/05/18YYYY MM DD - 1974 05 18MM/DD/YYYY - 05/18/1974%python-mtzolkin_calendar05/18/1974Gregorian "05/18/1974" is "12 Akʼbʼal" as Tzolk’inSearching Tzolk’in DatesTo search for Gregorian Dates to a given Tzolk’in date, input the Tzolk’in date to search for.As default the search is started today (the 24th of March, 2021). So, we search for "13 Lamat"%python-mtzolkin_calendar13LamatTzolk’in date "13 Lamat" next date is "24.08.2021", last date has been "07.12.2020"The next gregorian date with a Tzolk’in date of "12 Lamat" after today (the 24th of March 2021) is the 24th od August, 2021, the last gregorian date before today has been the 7th of December 2020.We again can use many formats to pass as Tzolk’in dates:DD NNNN - 13 LamatDD/NNNN - 13/LamatDD.NNNN - 13.LamatDD-NNNN - 13-LamatInstead of the name, we can also use the number of the day name (between 1 and 20), so instead of "Lamat" we could use the number 8. The valid formats are again (with or without leading zeroes).DD NN - 13 8DD/NN - 13/8DD.NN - 13.8DD-NN - 13-8We can also search starting at other days than today, so lets start the search at the 18th of May 1974, this is the argument to--start%python-mtzolkin_calendar13Lamat--start18.05.1974Tzolk’in date "13 Lamat" next date is "31.08.1974", last date has been "14.12.1973"Now the search returned the 31th of August, 1974 as the next and the 14th of December 1974 as the last Gregorian date with
the same Tzolk’in date.We can also search for more than one date in the future and the past, by using the argument--list, which is the number of Gregorian dates to return. Lets search for 5 Gregorian dates with a Tzolk’in date of "13 Lamat", starting at the 18th of May, 1974.%python-mtzolkin_calendar13Lamat--start18.05.1974--list5Tzolk’in date "13 Lamat"
     next dates are ['31.08.1974', '18.05.1975', '02.02.1976', '19.10.1976', '06.07.1977']
     last dates have been ['14.12.1973', '29.03.1973', '12.07.1972', '26.10.1971', '08.02.1971']So we're getting 5 Gregorian dates after and before the 18th of May, 1974.Without an--startargument, we start the search today (the 24th of March, 2021).%python-mtzolkin_calendar13Lamat--list5Tzolk’in date "13 Lamat"
     next dates are ['24.08.2021', '11.05.2022', '26.01.2023', '13.10.2023', '29.06.2024']
     last dates have been ['07.12.2020', '22.03.2020', '06.07.2019', '19.10.2018', '01.02.2018']We can make the list as long as we want, but if the list would be too long, we ran out of the valid calendar days.%python-mtzolkin_calendar13Lamat--list10000Traceback(mostrecentcalllast):...File"./tzolkin_calendar/calculate.py",line432,inlastTzolkinreturnstarting+day_diff_deltaOverflowError:datevalueoutofrangePrint all Tzolk’in Dates in a Tzolk’in YearTo get a list of all 260 Tzolk’in dates in a Tzolk’in year, we use the argument--year:%python-mtzolkin_calendar--year1 Imix 2 Ikʼ 3 Akʼbʼal 4 Kʼan 5 Chikchan 6 Kimi 7 Manikʼ 8 Lamat 9 Muluk 10 Ok 11 Chuwen 12 Ebʼ 13 Bʼen
     1 Ix
     ...
                                                                                                  13 Manikʼ
     1 Lamat 2 Muluk 3 Ok 4 Chuwen 5 Ebʼ 6 Bʼen 7 Ix 8 Men 9 Kʼibʼ 10 Kabʼan 11 Etzʼnabʼ 12 Kawak 13 Ajaw
    Gregorian "24.03.2021" is "3 Men" as Tzolk’inUsing the Jupyter NotebookYou can test it online at. You need to restart the kernel first
by going to the menu and selectingKernel->Restart & Run Allto get the interactive
sliders and input fields.You can get Information about Jupyter Notebooks at theofficial siteInstall Jupyter Notebook and ipywidgetspython-mpipinstallnotebookipywidgetsIf you want to be able to open the Jupyter notebook files directly, installnbopen.python-mpipinstallnbopenand add the extension to the list of extensions of your OS, so that you can double click
the.ipynbfiles and Jupyter opens it.On Linux:python-mnbopen.install_xdgOn Windows:python-mnbopen.install_winFor OS X, the installation is a bit more advanced, seenbopenDownload the Tzolk’in calendar notebook atTzolk’in Calendar.ipynbOpen it in Jupyter Notebook and run all cells, by going to the menu and usingKernel->Restart & Run All.You should now see something like:)Using the Python Module in Your ProgramsSee the second Jupyter Notebook about how to use the tzolkin-calendar module:Import the ModuleTo use the Tzolk’in date package, importtzolkin_calender(with an underscore_).A short check to see if it is working is to print the version oftzolkin-calendar, that's the constanttzolkin_calendar.VERSION.# Import the package.importtzolkin_calendar# Check, if it is working.tzolkin_calendar.VERSION'0.9.3'The Tzolk’in Date ClassTzolkinThe Tzolk’in date class resides in the moduletzolkin_calendar.tzolkin, and is namedTzolkin.So, import that module:# Import the module tzolkin that contains `Tzolkin`.fromtzolkin_calendarimporttzolkinConvert Gregorian Dates to Tzolk’in DatesTo get the Tzolk’in date of today, call the static methodfromToday. This returns aTzolkininstance holding the
Tzolk’in date of today ('today' is the 24th of March, 2021, with a Tzolk’in date of '3 Men')tzolkin.Tzolkin.fromToday()3 MenYou can generate aTzolkininstance from any gregorian date using thedatetime.dateclass or a date string.So, first import the datetime module:importdatetimeAnd then use the 3 possibilities to set the Tzolk’in date from a gregorian date. Or, in other words, to convert a gregorian date to a Tzolk’in date.from a datetime.date instance usingTzolkin.fromDate. We use the methodfromisoformatto set the gregorian date to the
24th of March 2021 with the date string '2021-03-24'. The Tzolk’in date of the 24th of March 2021 is '3 Men'.gregorian_date=datetime.date.fromisoformat("2021-03-24")tzolkin.Tzolkin.fromDate(gregorian_date)3 Menfrom an ISO date string usingTzolkin.fromIsoFormat. We set the Tzolk’in date to the 24th of March 2021 with the ISO date
string '2021-03-24'. The Tzolk’in date of the 24th of March 2021 is '3 Men'.tzolkin.Tzolkin.fromIsoFormat("2021-03-24")3 Menfrom an arbitrary date string usingTzolkin.fromDateString. We set the Tzolk’in date to the 24th of March 2021 with the date string '24=03*2021' and the format stringfmt'%d=%m*%Y'. The Tzolk’in date of the 24th of March 2021 is '3 Men'.tzolkin.Tzolkin.fromDateString("24=03*2021",fmt="%d=%m*%Y")3 MenSet Tzolk’in DatesYou can set theTzolkininstance to a Tzolk’in Date using it's constructor. The constructor takes the Tzolk’in day number (between 1 and 13 including 1 and 13) and either a Tzolk’in day name or the number of the Tzolk’in day name (between 1 and 20 , including 1 and 20).To get a dictionary of Tzolk’in day names and numbers, look attzolkin.day_names.tzolkin.day_names{1: 'Imix', 2: 'Ikʼ', 3: 'Akʼbʼal', 4: 'Kʼan', 5: 'Chikchan', 6: 'Kimi',
     7: 'Manikʼ', 8: 'Lamat', 9: 'Muluk', 10: 'Ok', 11: 'Chuwen', 12: 'Ebʼ',
     13: 'Bʼen', 14: 'Ix', 15: 'Men', 16: 'Kʼibʼ', 17: 'Kabʼan', 18: 'Etzʼnabʼ',
     19: 'Kawak', 20: 'Ajaw'}If we want to set a Tzolk’in day of '8 Kabʼan', we can either pass the day number 8 and day name Kabʼan to the constructor, or
the day number 8 and the day name number 17.tzolkin.Tzolkin(number=8,name_str="Kabʼan")8 Kabʼantzolkin.Tzolkin(number=8,name_number=17)8 KabʼanIf we pass an invalid number (not in [1, 13]) or name to the constructor, we get aTzolkinException.tzolkin.Tzolkin(number=53,name_number=17)TzolkinException:number53isnotavalidTzolkindaynumber,notbetween1and13(including1and13)tzolkin.Tzolkin(number=3,name_str="Hugo")TzolkinException:string"Hugo"isnotavalidTzolkindayname,oneof:dict_values(['Imix','Ikʼ','Akʼbʼal','Kʼan','Chikchan','Kimi','Manikʼ','Lamat','Muluk','Ok','Chuwen','Ebʼ','Bʼen','Ix','Men','Kʼibʼ','Kabʼan','Etzʼnabʼ','Kawak','Ajaw'])tzolkin.Tzolkin(number=3,name_number=-5)TzolkinException:-5isnotavalidTzolkindaynamenumber,itmustbebetween1and20(including1and20)These Tzolk’in day numbers and names can be accessed using the methodsgetDayNumber,getDayNameandgetDayNameNumber.# Set the Tzolk’in date to '12 Kimi'.tzolkin_date=tzolkin.Tzolkin(number=12,name_str="Kimi")tzolkin_date.getDayNumber()12tzolkin_date.getDayName()'Kimi'tzolkin_date.getDayNameNumber()6To get the number of Tzolk’in day in the Tzolk’in year of 260 days, there isgetTzolkinYearDay. For example '12 Kimi' is the 246. day (of 260 days)  of the Tzolk’in yeartzolkin_date.getTzolkinYearDay()246To parse a Tzolk’in day name that isn't exactly like the ones intzolkin.day_names(see [8]), there is the methodTzolkin.parseTzolkinName, that ignores upper- and lowercase and all non-alphanumeric and non-ascii characters.day_number=tzolkin.Tzolkin.parseTzolkinName("EtZ`nAB")ifday_number!=0:tzolkin_name=tzolkin_calendar.day_names[day_number]tzolkin_name'Etzʼnabʼ'All 260 Tzolk’in days of a Tzolk’in year we can get as a list of strings from the static methodgetTzolkinCalendar.tzolkin.Tzolkin.getTzolkinCalendar()['1 Imix', '2 Ikʼ', '3 Akʼbʼal', '4 Kʼan', '5 Chikchan', '6 Kimi', '7 Manikʼ', '8 Lamat', '9 Muluk', '10 Ok',
     '11 Chuwen',
     ...
                                                                                    '1 Lamat', '2 Muluk', '3 Ok',
     '4 Chuwen', '5 Ebʼ', '6 Bʼen', '7 Ix', '8 Men', '9 Kʼibʼ', '10 Kabʼan', '11 Etzʼnabʼ', '12 Kawak', '13 Ajaw']Search Gregorian Dates to a given Tzolk’in DateWe can search for the next (forward in time) or last (backwards in time) day with the same Tzolk’in date using the methodsgetNextDateandgetLastDate. Both methods return adatetime.dateobject.When searching for the next gregorian date that has the Tzolk’in date '7 Kawak', we get the 28th of March, 2021 - because we started searching 'today', which is the 24th of March 2021.# Set the Tzolk’in date to search for to '7 Kawak'.tzolkin_date=tzolkin.Tzolkin(number=7,name_str="Kawak")tzolkin_date.getNextDate()datetime.date(2021, 3, 28)When searching for the last gregorian date that has the Tzolk’in date '7 Kawak', we get the 11th of July, 2020 - because we started searching 'today', which is the 24th of March 2021.tzolkin_date.getLastDate()datetime.date(2020, 7, 11)Both methods,getNextDateandgetLastDatetake an optional argumentstart_date, which is the gregorian date to start
the search. If nostart_dateis given, 'today' is used as the start date.So now we search again for '7 Kawak' in both directions, but this time we start at the 10th of July, 2020.# Set the Tzolk’in date to search for to '7 Kawak'.tzolkin_date=tzolkin.Tzolkin(number=7,name_str="Kawak")# Set the start date of the search to the 10th of July, 2020.start_search=datetime.date.fromisoformat("2020-07-10")start_search.isoformat()'2020-07-10'For the next day with a Tzolk’in date of '7 Kawak' we now get the 11th of July, 2020.tzolkin_date.getNextDate(start_date=start_search)datetime.date(2020, 7, 11)For the last day before our start date with a Tzolk’in date of '7 Kawak' we now get the 25th of October, 2019.tzolkin_date.getLastDate(start_date=start_search)datetime.date(2019, 10, 25)To get a list ofdatetime.datedates with the same Tzolk’in date, we can use the methodsgetNextDateListandgetLastDateList.Again, we can set the argumentstart_dateto a gregorian date to start the search or not set it to start the search today.
The number of elements in the returned list is set using the parameterlist_size, which defaults to 50.Let's start the search for dates with a Tzolk’in date of ' 7 Kawak' today, the 24th of March 2021, and set the list size to 9 elements:# Set the Tzolk’in date to search for to '7 Kawak'.tzolkin_date=tzolkin.Tzolkin(number=7,name_str="Kawak")tzolkin_date.getNextDateList(list_size=9)[datetime.date(2021, 3, 28),
     datetime.date(2021, 12, 13),
     datetime.date(2022, 8, 30),
     datetime.date(2023, 5, 17),
     datetime.date(2024, 2, 1),
     datetime.date(2024, 10, 18),
     datetime.date(2025, 7, 5),
     datetime.date(2026, 3, 22),
     datetime.date(2026, 12, 7)]Now start searching for '7 Kawak' on the 29th of March, 2021 and set the returned list size to 5.# Set the start date of the search to the 29th of March, 2021.start_search=datetime.date.fromisoformat("2021-03-29")tzolkin_date.getLastDateList(start_date=start_search,list_size=5)[datetime.date(2021, 3, 28),
     datetime.date(2020, 7, 11),
     datetime.date(2019, 10, 25),
     datetime.date(2019, 2, 7),
     datetime.date(2018, 5, 23)]Calculations using  Tzolk’in DatesThere are 4 methods to get the difference in days between two Tzolk’in dates and to add (or subtract) days from a Tzolk’in date:addDays,addTimedelta,getDayDiffandgetDayTimedelta.Lets start with a Tzolk’in date of '6 Muluk'.tzolkin.Tzolkin(number=6,name_str="Muluk")6 MulukAdd 6 days to it, and we get a Tzolk’in date of '12 Men'.tzolkin.Tzolkin(number=6,name_str="Muluk").addDays(6)12 MenInstead of using ints, we can also add and subtractdatetime.timedeltaobjects.
Now subtract 6 days from '12 Men' - we get '6 Muluk'.to_subtract=datetime.timedelta(days=-6)tzolkin.Tzolkin(number=12,name_str="Men").addTimedelta(to_subtract)6 MulukTo get the difference between two Tzolk’in dates there exist the MethodsgetDayDiffandgetDayTimedelta.Lets calculate the difference in days between '6 Muluk' and '12 Men'.# Set start_tzolkin to '6 Muluk'.start_tzolkin=tzolkin.Tzolkin(number=6,name_str="Muluk")# Set end_tzolkin to '12 Men'.end_tzolkin=tzolkin.Tzolkin(number=12,name_str="Men")start_tzolkin.getDayDiff(end_tzolkin)6And usinggetDayTimedelta, which returns adatetime.timedeltaobject.start_tzolkin.getDayTimedelta(end_tzolkin)datetime.timedelta(days=6)What happens, if we calculate the difference between '12 Men' and '6 Muluk'?end_tzolkin.getDayDiff(start_tzolkin)254We get 254 days, not -6. That's because the difference is always calculated forward in time. If you want to get negative days or the shortest possible time difference, subtract 260 from the the result (the number of days in a Tzolk’in year). As soon as the difference in days is greater than 130, to minimum time distance in days 'is negative'.day_diff=end_tzolkin.getDayDiff(start_tzolkin)ifday_diff>130:day_diff=260-day_diffday_diff6Or you can use the minimum ofresultand|result - 260|that isabs(result - 260).day_diff=end_tzolkin.getDayDiff(start_tzolkin)shortest_diff=min(day_diff,abs(day_diff-260))shortest_diff6More informationDetailed information is available at thedocumentation website.ContributingAny help is welcome!If you encounter a problem using tzolkin-calendar, a task it not as easy as you'd like it to be
or you'd like something added to it: open an issue at GitHub.Report Issues (Bugs and Feature Requests)File a bug report atGithubAdd a feature request atGithubChanging the Documentation and Source CodeIf you'd like to contribute directly, e.g. better the documentation, add another language or
write some source code: fork tzolkin-calendar by clicking theFork-button in the upper right
corner of theGitHub project website.
Check out your fork of tzolkin-calendar using the URL from theCode-button of your fork on Github.
The URL should be something likegithub.com/YOUR_USERNAME/tzolkin-calendar.git.Details about how to fork a repository on Github arehereand set up the development environment using pipenv.First, install pipenv if you don't already have it installed:python-mpipinstall--upgradepipenvand install all needed packages to develop tzolkin-calender:cdtzolkin-calendar
python-mpipenvinstall--devThat command installs all packages inPipfile/Pipfile.lockin the directorytzolkin-calender,
the root directory of tzolkin-calendar.More information about pipenv can be found atPipenv.Make your changes, push them to your forked repository and make a pull-request (e.g.
using thePull request-button above and right of GitHubs source file view).SeeGitHub on Pull-RequestsGithub Documentation on Collaborating with Issues and Pull RequestsSee GitHub's documentation about how to contribute for details:Contributing at GithubMore InformationDetailed information is available at thedocumentation website: ContributingLicenseEverything intzolkin-calendaris licensed under the MIT license, see fileLICENSEBadgesExternal ChecksStatic Code ChecksTestsProblem with Unicode output on GitHub's Windows 2019 Server:, seeIssue #1