tzolkin_calendar Package

This is the source code reference documentation, autogenerated from tzolkin-calendar’s source code.

Submodules

tzolkin_calendar.tzolkin module

tzolkin_calendar.calculate module

This modules holds functions needed to calculate with Tzolkin calendar dates and convert them to and from gregorian dates.

Example:

>>> import datetime
>>> import tzolkin_calendar.calculate
>>> tzolkin_calendar.calculate.gregorian2tzolkin(datetime.datetime.strptime("23.05.2014", "%d.%m.%Y"))
2 Etzʼnabʼ (𕐚)
>>> import datetime
>>> import tzolkin_calendar.calculate
>>> tzolkin_calendar.calculate.nextTzolkin(tzolkin_calendar.TzolkinDate(name=3, number=5))
datetime.date(2021, 4, 21)
>>> import datetime
>>> import tzolkin_calendar.calculate
>>> tzolkin_calendar.calculate.lastTzolkin(tzolkin_calendar.TzolkinDate(name=17, number=3))
datetime.date(2021, 1, 5)
>>> import datetime
>>> import tzolkin_calendar.calculate
>>> tzolkin_calendar.calculate.tzolkin2gregorian(tzolkin_calendar.TzolkinDate(name="2", number="7"),start=datetime.date.today())
[datetime.date(2021, 10, 15), datetime.date(2022, 7, 2), datetime.date(2023, 3, 19), datetime.date(2023, 12, 4),
>>> import datetime
>>> import tzolkin_calendar.calculate
>>> tzolkin_calendar.calculate.tzolkin2gregorian(tzolkin_calendar.TzolkinDate(name="2", number="7"), forward=False, start=datetime.date.today())
[datetime.date(2021, 10, 15), datetime.date(2021, 1, 28), datetime.date(2020, 5, 13), datetime.date(2019, 8, 27),
calculateTzolkinName(start_name: int, to_add: int)int

Return the Tzolkin name to_add days after start_name. Add or subtracts the given integer to the index of the Tzolkin name and return the index of the new name. Adds to_add to the name index start_name and takes the value modulo 20. If the result would be 0, return 20 instead.

Parameters
  • start_name (int) – The index of the name to add days to.

  • to_add (int) – The number of days to add to the Tzolkin name.

Returns

The index of the resulting Tzolkin name, to_add days after start_name.

Return type

int

calculateTzolkinNumber(start_number: int, to_add: int)int

Return the Tzolkin number to_add days after start_number. Add or subtracts the given integer to the Tzolkin number and return the new number. Adds to_add to the number start_name and takes the value modulo 13. If the result would be 0, return 13 instead.

Parameters
  • start_number (int) – The number to add the days to.

  • to_add (int) – The number of days to add to the Tzolkin number.

Returns

The resulting number to_add days after start_number.

Return type

int

getTzolkinDay(tzolkin: tzolkin_calendar.TzolkinDate)int

Return the day number in the Tzolkin year, in the interval [1,260] (including both 1 and 260). That is, the index of the given Tzolkin date in the 260 day Tzolkin year. 1 Imix yields 1 (the first day of the year), 13 Ajaw yields 260, the last day of the Tzolkin year. If the given date tzolkin does not exist, 0 is returned.

Parameters

tzolkin (TzolkinDate) – The Tzolkin date to get the day in the year of.

Returns

The day of the given date in the Tzolkin year, a positive integer between

and including 1 and 260. If the given date does not exist, 0 is returned.

Return type

int

getTzolkinDiff(start: tzolkin_calendar.TzolkinDate, end: tzolkin_calendar.TzolkinDate)int

Return the difference in days between the two given Tzolkin dates. No negative differences are returned, but the number of days to reach the end date if starting from start. If start is earlier than end the difference is start - end. If end is before start, 260 - start + end (same as 260 - (end - start)) is returned.

Example

getTzolkinDiff returns 12 for start = 4 Manikʼ and end = 3 Kawak

>>> getTzolkinDiff(
        start=tzolkin_calendar.TzolkinDate(number=4, name=7),
        end=tzolkin_calendar.TzolkinDate(number=3, name=19),
    ) == 12

getTzolkinDiff returns 250 for start = 8 Chuwen and end = 11 Imix

>>> getTzolkinDiff(
        start=tzolkin_calendar.TzolkinDate(number=8, name=11),
        end=tzolkin_calendar.TzolkinDate(number=11, name=1),
    ) == 250
Parameters
  • start (TzolkinDate) – The Tzolkin date to start the calculation from.

  • end (TzolkinDate) – The Tzolkin date to calculate the time difference in days to.

Returns

The number of days between the two given dates. Never negative (0 if start and end are the same day).

Return type

int

gregorian2tzolkin(date: datetime.date)tzolkin_calendar.TzolkinDate

Return the Tzolkin date of the given gregorian date.

Parameters

date (datetime.date) – The gregorian date to convert to Tzolkin.

Returns

The Tzolkin date of the given day date.

Return type

TzolkinDate

lastTzolkin(tzolkin: tzolkin_calendar.TzolkinDate, starting: datetime.date = datetime.date(2021, 3, 29))datetime.date

Return the last gregorian date before starting, that has a Tzolkin date of tzolkin. Search backwards in time for a day with the Tzolkin date tzolkin.

Parameters
  • tzolkin (TzolkinDate) – The Tzolkin date to search for.

  • starting (datetime.date, optional) – The date to start the search. Defaults to datetime.date.today().

Returns

The last gregorian date with the given Tzolkin date tzolkin

before starting.

Return type

datetime.date

makeLookUpTable()Dict[int, tzolkin_calendar.TzolkinDate]

Return a dictionary holding all TzolkinDate instances of a tzolkin year. The tzolkin year consists of all combinations of day_names and ay_numbers, day_numbers are the numbers from 1 to 13 and day_names the names from ‘Imix’ to ‘Ajaw’. So a Tzolkin year is: 1 Imix, 2 Ik’, 3 Ak’b’al, … and finishes at 12 Kawak and finally 13 Ajaw.

Returns

The dictionary of all tzolkin date combinations in a

tzolkin year (of 260 days).

Return type

Dict[int, TzolkinDate]

nextTzolkin(tzolkin: tzolkin_calendar.TzolkinDate, starting: datetime.date = datetime.date(2021, 3, 29))datetime.date

Return the next gregorian date after starting, that has a Tzolkin date of tzolkin. Search forward in time for a day with Tzolkin date tzolkin.

Parameters
  • tzolkin (TzolkinDate) – The Tzolkin date to search for.

  • starting (datetime.date, optional) – The date to start the search. Defaults to datetime.date.today().

Returns

The next gregorian date with the given Tzolkin date tzolkin

after starting.

Return type

datetime.date

parseTzolkinName(name_str: str)int

Parse the given string to get a Tzolkin day name. Ignores lower- and uppercase, ignores all non-alphanumberic characters.

Returns 0 if no name has been found

Parameters

name_str (str) – The string to parse to get a Tzolkin day name.

Returns

The number of the found Tzolkin day name. 0 on errors.

Return type

int

tzolkin2gregorian(tzolkin: tzolkin_calendar.TzolkinDate, start: datetime.date, num_results: int = 100, forward: bool = True)List[datetime.date]

Return a list of dates having the same Tzolkin date as the given date tzolkin.

If num_results is smaller than 1, an empty list is returned.

Parameters
  • tzolkin (TzolkinDate) – The Tzolkin date to search for.

  • start (datetime.date) – The gregorian date to start the search from.

  • num_results (int, optional) – The number of results to return. If this is < 1, an empty list is returned. Defaults to 100.

  • forward (bool, optional) – The direction in time to search. Either forward (if

  • is True) or backwards (forward) –

Returns

The list of gregorian dates having the same Tzolkin date as

tzolkin. The number of elements of this list is num_results.

Return type

List[datetime.date]

tzolkin_calendar.main module