Mayan calendar: Difference between revisions

Content deleted Content added
Peak (talk | contribs)
 
(24 intermediate revisions by 8 users not shown)
Line 212:
2020-02-29
2020-03-01
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">
V _DAYS_IN_MONTH = [-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
 
V _DAYS_BEFORE_MONTH = [-1]
V dbm = 0
L(dim) _DAYS_IN_MONTH[1..]
_DAYS_BEFORE_MONTH.append(dbm)
dbm += dim
 
F _days_before_year(year)
‘year -> number of days before January 1st of year.’
V y = year - 1
R y * 365 + y I/ 4 - y I/ 100 + y I/ 400
 
F _is_leap(year)
‘year -> 1 if leap year, else 0.’
R year % 4 == 0 & (year % 100 != 0 | year % 400 == 0)
 
F _days_before_month(year, month)
‘year, month -> number of days in year preceding first day of month.’
R :_DAYS_BEFORE_MONTH[month] + (month > 2 & _is_leap(year))
 
F _ymd2ord(year, month, day)
‘year, month, day -> ordinal, considering 01-Jan-0001 as day 1.’
R (_days_before_year(year) + _days_before_month(year, month) + day)
 
F g2m(date, gtm_correlation = 1B)
V correlation = I gtm_correlation {584283} E 584285
 
V long_count_days = [144000, 7200, 360, 20, 1]
 
V tzolkin_months = ["Imix'", "Ik'", "Ak'bal", "K'an", ‘Chikchan’, ‘Kimi’, "Manik'", ‘Lamat’, ‘Muluk’, ‘Ok’, ‘Chuwen’,
‘Eb’, ‘Ben’, ‘Hix’, ‘Men’, "K'ib'", ‘Kaban’, "Etz'nab'", ‘Kawak’, ‘Ajaw’]
 
V haad_months = [‘Pop’, "Wo'", ‘Sip’, "Sotz'", ‘Sek’, ‘Xul’, "Yaxk'in", ‘Mol’, "Ch'en", ‘Yax’, "Sak'", ‘Keh’, ‘Mak’,
"K'ank'in", ‘Muwan’, ‘Pax’, "K'ayab", "Kumk'u", "Wayeb'"]
 
V (year, month, day) = date.split(‘-’).map(Int)
V gregorian_days = _ymd2ord(year, month, day)
V julian_days = gregorian_days + 1721425
 
[Int] long_date
V remainder = julian_days - correlation
 
L(days) long_count_days
(V result, remainder) = divmod(remainder, days)
long_date.append(Int(result))
 
V long_date_str = (long_date.map(d -> ‘#02’.format(d))).join(‘.’)
 
V tzolkin_month = (julian_days + 16) % 20
V tzolkin_day = ((julian_days + 5) % 13) + 1
 
V haab_month = Int(((julian_days + 65) % 365) / 20)
V haab_day = ((julian_days + 65) % 365) % 20
V haab_day_str = I haab_day {String(haab_day)} E ‘Chum’
 
V lord_number = (julian_days - correlation) % 9
lord_number = I lord_number {lord_number} E 9
 
V round_date = tzolkin_day‘ ’tzolkin_months[tzolkin_month]‘ ’haab_day_str‘ ’haad_months[haab_month]‘ G’lord_number
 
R (long_date_str, round_date)
 
V dates = [‘2004-06-19’, ‘2012-12-18’, ‘2012-12-21’, ‘2019-01-19’, ‘2019-03-27’, ‘2020-02-29’, ‘2020-03-01’]
L(date) dates
V (long, round_date) = g2m(date)
print(date‘ ’long‘ ’round_date)
</syntaxhighlight>
 
{{out}}
<pre>
2004-06-19 12.19.11.06.13 4 Ben 16 Sotz' G7
2012-12-18 12.19.19.17.17 1 Kaban Chum K'ank'in G6
2012-12-21 13.00.00.00.00 4 Ajaw 3 K'ank'in G9
2019-01-19 13.00.06.03.00 1 Ajaw 13 Muwan G6
2019-03-27 13.00.06.06.07 3 Manik' Chum Wayeb' G1
2020-02-29 13.00.07.05.06 4 Kimi 14 K'ayab G7
2020-03-01 13.00.07.05.07 5 Manik' 15 K'ayab G8
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <chrono>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
 
const std::vector<std::string> Tzolkin = { "Imix'", "Ik'", "Ak'bal", "K'an", "Chikchan", "Kimi", "Manik'",
"Lamat", "Muluk", "Ok", "Chuwen", "Eb", "Ben", "Hix", "Men", "K'ib'", "Kaban", "Etz'nab'", "Kawak", "Ajaw" };
 
const std::vector<std::string> Haab = { "Pop", "Wo'", "Sip", "Sotz'", "Sek", "Xul", "Yaxk'in", "Mol",
"Ch'en", "Yax", "Sak'", "Keh", "Mak", "K'ank'in", "Muwan", "Pax", "K'ayab", "Kumk'u", "Wayeb'" };
 
 
int32_t positive_modulus(const int32_t& base, const int32_t& modulus) {
const int32_t result = base % modulus;
return ( result < 0 ) ? result + modulus : result;
}
 
std::chrono::sys_days create_date(const std::string& iso_date) {
const int year = std::stoi(iso_date.substr(0, 4));
const unsigned int month = std::stoi(iso_date.substr(5, 7));
const unsigned int day = std::stoi(iso_date.substr(8, 10));
 
std::chrono::year_month_day date{std::chrono::year{year}, std::chrono::month{month}, std::chrono::day{day}};
return std::chrono::sys_days(date);
}
 
const std::chrono::sys_days CREATION_TZOLKIN = create_date("2012-12-21");
const std::chrono::sys_days ZERO_HAAB = create_date("2019-04-02");
 
int32_t days_per_mayan_month(const std::string& month) {
return ( month == "Wayeb'" ) ? 5 : 20;
}
 
std::string tzolkin(const std::chrono::sys_days& gregorian) {
const int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count();
int32_t remainder = positive_modulus(days_between, 13);
remainder += ( remainder <= 9 ) ? 4 : -9;
return std::to_string(remainder) + " " + Tzolkin[positive_modulus(days_between - 1, 20)];
}
 
std::string haab(const std::chrono::sys_days& gregorian) {
const int32_t days_between = ( gregorian - ZERO_HAAB ).count();
int32_t remainder = positive_modulus(days_between, 365);
const std::string month = Haab[positive_modulus(remainder + 1, 20)];
const int32_t day_of_month = remainder % 20 + 1;
return ( day_of_month < days_per_mayan_month(month) ) ?
std::to_string(day_of_month) + " " + month : "Chum " + month;
}
 
std::string long_count(const std::chrono::sys_days& gregorian) {
int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count() + 13 * 360 * 400;
const int32_t baktun = positive_modulus(days_between, 360 * 400);
days_between = days_between % ( 360 * 400 );
const int32_t katun = days_between / ( 20 * 360 );
days_between = days_between % ( 20 * 360 );
const int32_t tun = days_between / 360;
days_between = days_between % 360;
const int32_t winal = days_between / 20;
const int32_t kin = days_between % 20;
 
std::string result = "";
for ( int32_t number : { baktun, katun, tun, winal, kin } ) {
std::string value = std::to_string(number) + ".";
result += ( number <= 9 ) ? "0" + value : value;
}
return result.substr(0, result.length() - 1);
}
 
std::string lords_of_the_night(const std::chrono::sys_days& gregorian) {
const int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count();
const int32_t remainder = days_between % 9;
return "G" + std::to_string( ( remainder <= 0 ) ? remainder + 9 : remainder );
}
 
int main() {
const std::vector<std::string> iso_dates = { "2004-06-19", "2012-12-18", "2012-12-21", "2019-01-19",
"2019-03-27", "2020-02-29", "2020-03-01", "2071-05-16", "2020-02-02" };
 
std::cout << "Gregorian Long Count Tzolk'in Haab' Lords of the Night" << std::endl;
std::cout << "------------------------------------------------------------------------------" << std::endl;
for ( const std::string& iso_date : iso_dates ) {
const std::chrono::sys_days date = create_date(iso_date);
 
std::cout << std::left << std::setw(15) << iso_date << std::setw(19) << long_count(date)
<< std::setw(12) << tzolkin(date) << std::setw(18) << haab(date)
<< lords_of_the_night(date) << std::endl;
}
}
</syntaxhighlight>
{{ out }}
<pre>
Gregorian Long Count Tzolk'in Haab' Lords of the Night
------------------------------------------------------------------------------
2004-06-19 12.19.11.06.13 4 Ben 16 Sotz' G7
2012-12-18 12.19.19.17.17 1 Kaban Chum K'ank'in G6
2012-12-21 13.00.00.00.00 4 Ajaw 3 K'ank'in G9
2019-01-19 13.00.06.03.00 1 Ajaw 13 Muwan G6
2019-03-27 13.00.06.06.07 3 Manik' Chum Wayeb' G1
2020-02-29 13.00.07.05.06 4 Kimi 14 K'ayab G7
2020-03-01 13.00.07.05.07 5 Manik' 15 K'ayab G8
2071-05-16 13.02.19.04.10 1 Ok 18 Sip G9
2020-02-02 13.00.07.03.19 3 Kawak 7 Pax G7
</pre>
 
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">
<lang Fortran>
PROGRAM MAYA_DRIVER
IMPLICIT NONE
Line 281 ⟶ 473:
intent(in) :: day,month,year
!
integer(kind=4) :: j,l, numdays, savedays, keptdays
integer(kind=4) :: kin_no, winal_no, tun_no, katun_no, baktun_no, longcount_no
character(*) :: haab_carry, nightlord, tzolkin_carry, long_carry
Line 287 ⟶ 479:
integer :: mo,da
!
! 2071-05-16
! 1963-11-21
keptdays = julday(day,month,year) ! Get the Julian date for selected date
numdays = keptdays ! Keep for calcs later
! Adjust from the beginning
numdays = numdays-startdate ! Adjust the number of days from start of Mayan Calendar
savedays = numdays ! Save for later when we canculate Haab etc.
if (numdays .ge. longcount)then ! We check if we have passed a longcount and need to adjust for a new start
longcount_no = numdays/longcount
Line 316 ⟶ 505:
!
haab_carry = " "
keptdays = julday(day,month,year)
L = mod((keptdays+65),365)
mo = (L/20)+1
Line 328 ⟶ 516:
! Ok, Now let's calculate the Tzolk´in
! The calendar starts on the 4 Ahu
keptdays = julday(day,month,year)
tzolkin_carry = " " ! Total blank the carrier
mo = mod((keptdays+16),20) + 1
Line 380 ⟶ 567:
END SUBROUTINE maya_time
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
16-5-2071 1 Ok 18 Sip 13.02.19.04.10 (G9) Tlaloc
19-6-2004 4 Ben 16 Sotz´ 12.19.11.06.13 (G7) Tlazolteotl
18-12-2012 1 Kaban Chum K´ank´in 12.19.19.17.17 (G6) Chalchiuhtlicue
21-12-2012 4 Ajaw 3 K´ank´in 13.00.00.00.00 (G9) Tlaloc
19-1-2019 1 Ajaw 13 Muwan 13.00.06.03.00 (G6) Chalchiuhtlicue
27-3-2019 3 Manik´ Chum Wayeb´ 13.00.06.06.07 (G1) Xiuhtecuhtli
29-2-2020 4 Kimi 14 K´ayab 13.00.07.05.06 (G7) Tlazolteotl
1-3-2020 5 Manik´ 15 K´ayab 13.00.07.05.07 (G8) Tepeyollotl
 
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 484 ⟶ 683:
fmt.Printf("%s %2d %-8s %4s %-9s %-14s %s\n", dt, n, s, d, m, lc, l)
}
}</langsyntaxhighlight>
 
{{out}}
Line 499 ⟶ 698:
2020-03-01 5 Manik’ 15 K’ayab 13.0.7.5.7 G8
2071-05-16 1 Ok 18 Sip 13.2.19.4.10 G9
</pre>
 
=={{header|J}}==
 
Implementation:
<syntaxhighlight lang="j">require 'types/datetime'
 
NB. 1794214= (0 20 18 20 20#.13 0 0 0 0)-todayno 2012 12 21
longcount=: {{ rplc&' .'":0 20 18 20 20#:y+1794214 }}
 
tsolkin=: (cut {{)n
Imix’ Ik’ Ak’bal K’an Chikchan
Kimi Manik’ Lamat Muluk Ok
Chuwen Eb Ben Hix Men
K’ib’ Kaban Etz’nab’ Kawak Ajaw
}}-.LF){{ (":1+13|y-4),' ',(20|y-7){::m }}
 
haab=:(cut {{)n
Pop Wo’ Sip Sotz’ Sek Xul
Yaxk’in Mol Ch’en Yax Sak’ Keh
Mak K’ank’in Muwan Pax K’ayab Kumk’u
Wayeb’
}}-.LF){{
'M D'=.0 20#:365|y-143
({{ if.*y do.":y else.'Chum'end. }} D),' ',(M-0=D){::m
}}
 
round=: [:;:inv tsolkin;haab;'G',&":1+9|]
 
gmt=: >@(fmtDate;round;longcount)@todayno</syntaxhighlight>
 
J's <tt>todayno</tt> counts days from January 1, 1800. And, each of these date formatting routines expects a number generated by todayno, with hard coded offsets, if necessary, to make this work. (The lord of night number uses an offset of zero, in this context.)
 
Also, in haab, our 'chum' days are zeros from modulo arithmetic (and, thus, belong to the previous month).
 
Task examples:
<syntaxhighlight lang="j"> gmt 2004 6 19
June 19, 2004
4 Ben 16 Sotz’ G7
12.19.10.4.13
 
gmt 2012 12 18
December 18, 2012
1 Kaban Chum Mak G6
12.19.17.19.17
 
gmt 2012 12 21
December 21, 2012
4 Ajaw 3 K’ank’in G9
13.0.0.0.0
 
gmt 2019 1 19
January 19, 2019
1 Ajaw 13 Muwan G6
13.0.5.11.0
 
gmt 2019 3 27
March 27, 2019
3 Manik’ Chum Kumk’u G1
13.0.5.14.7
 
gmt 2019 2 29
March 1, 2019
3 Imix’ 14 K’ayab G2
13.0.5.13.1
 
gmt 2019 3 1
March 1, 2019
3 Imix’ 14 K’ayab G2
13.0.5.13.1</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
 
public final class MayanCalendar {
 
public static void main(String[] aArgs) {
List<LocalDate> testDates = List.of( LocalDate.parse("2004-06-19"),
LocalDate.parse("2012-12-18"),
LocalDate.parse("2012-12-21"),
LocalDate.parse("2019-01-19"),
LocalDate.parse("2019-03-27"),
LocalDate.parse("2020-02-29"),
LocalDate.parse("2020-03-01"),
LocalDate.parse("2071-05-16"),
LocalDate.parse("2020-02-02") );
System.out.println("Gregorian Long Count Tzolk'in Haab' Lords of the Night");
System.out.println("------------------------------------------------------------------------------");
for ( LocalDate date : testDates ) {
System.out.println(String.format("%-15s%-19s%-12s%-18s%s",
date.toString(), longCount(date), tzolkin(date), haab(date), lordsOfTheNight(date)));
}
}
private static String lordsOfTheNight(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(CREATION_TZOLKIN, aGregorian);
long remainder = Math.floorMod(daysBetween, 9);
return "G" + ( ( remainder <= 0 ) ? remainder + 9 : remainder );
}
private static String longCount(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(CREATION_TZOLKIN, aGregorian) + 13 * 360 * 400;
long baktun = Math.floorDiv(daysBetween, 360 * 400);
daysBetween = Math.floorMod(daysBetween, 360 * 400);
long katun = Math.floorDiv(daysBetween, 20 * 360);
daysBetween = Math.floorMod(daysBetween, 20 * 360);
long tun = Math.floorDiv(daysBetween, 360);
daysBetween = Math.floorMod(daysBetween, 360);
long winal = Math.floorDiv(daysBetween, 20);
long kin = Math.floorMod(daysBetween, 20);
StringBuilder result = new StringBuilder();
for ( long number : List.of( baktun, katun, tun, winal, kin ) ) {
String value = String.valueOf(number) + ".";
result.append( number <= 9 ? "0" + value : value );
}
return result.toString().substring(0, result.length() - 1);
}
private static String haab(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(ZERO_HAAB, aGregorian);
int remainder = Math.floorMod(daysBetween, 365);
String month = Haab.get(Math.floorDiv(remainder + 1, 20));
int dayOfMonth = Math.floorMod(remainder, 20) + 1;
return ( dayOfMonth < daysPerMayanMonth(month) ) ? dayOfMonth + " " + month : "Chum " + month;
}
 
private static String tzolkin(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(CREATION_TZOLKIN, aGregorian);
int remainder = Math.floorMod(daysBetween, 13);
remainder += ( remainder <= 9 ) ? 4 : -9;
return remainder + " " + Tzolkin.get(Math.floorMod(daysBetween - 1, 20));
}
private static int daysPerMayanMonth(String aMonth) {
return ( aMonth == "Wayeb'" ) ? 5 : 20;
}
private static List<String> Tzolkin = List.of( "Imix'", "Ik'", "Ak'bal", "K'an", "Chikchan", "Kimi", "Manik'",
"Lamat", "Muluk", "Ok", "Chuwen", "Eb", "Ben", "Hix", "Men", "K'ib'", "Kaban", "Etz'nab'", "Kawak", "Ajaw" );
 
private static List<String> Haab = List.of( "Pop", "Wo'", "Sip", "Sotz'", "Sek", "Xul", "Yaxk'in", "Mol",
"Ch'en", "Yax", "Sak'", "Keh", "Mak", "K'ank'in", "Muwan", "Pax", "K'ayab", "Kumk'u", "Wayeb'" );
private static final LocalDate CREATION_TZOLKIN = LocalDate.parse("2012-12-21");
private static final LocalDate ZERO_HAAB = LocalDate.parse("2019-04-02");
 
}
</syntaxhighlight>
{{ out }}
<pre>
Gregorian Long Count Tzolk'in Haab' Lords of the Night
------------------------------------------------------------------------------
2004-06-19 12.19.11.06.13 4 Ben 16 Sotz' G7
2012-12-18 12.19.19.17.17 1 Kaban Chum K'ank'in G6
2012-12-21 13.00.00.00.00 4 Ajaw 3 K'ank'in G9
2019-01-19 13.00.06.03.00 1 Ajaw 13 Muwan G6
2019-03-27 13.00.06.06.07 3 Manik' Chum Wayeb' G1
2020-02-29 13.00.07.05.06 4 Kimi 14 K'ayab G7
2020-03-01 13.00.07.05.07 5 Manik' 15 K'ayab G8
2071-05-16 13.02.19.04.10 1 Ok 18 Sip G9
2020-02-02 13.00.07.03.19 3 Kawak 7 Pax G7
</pre>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
 
'''Works with jq, the C implementation of jq'''
 
'''Works with gojq, the Go implementation of jq'''
 
In this entry, the functions for converting Gregorian dates to dates
in the Mayan calendar take the form of zero-arity filters that expect,
as input, strings of the form "yyyy-mm-dd" or JSON Date objects of the
form {"year", "month", "day"}.
 
<syntaxhighlight lang="jq">
### General utilities
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l) + .;
def rpad($len): tostring | ($len - length) as $l | . + (" " * $l);
 
# days_between("2020-01-01"; "2020-01-02") #=> 1
# days_between("2020-01-02"; "2020-01-01") #=> -1
def days_between($yyyymmddBefore; $yyyymmddAfter):
(yyyymmddBefore | strptime("%Y-%m-%d") | mktime) as $before
| (yyyymmddAfter | strptime("%Y-%m-%d") | mktime) as $after
# leap seconds are always inserted
| (($after - $before) / (24*60*60) | floor) ;
 
### `Date` objects
 
def Date($year; $month; $day): {$year, $month, $day};
 
# Convert a Date object to a string yyyy-mm-dd
# Other inputs are (currently) unscathed.
def yyyymmdd:
if type == "object" then "\(.year)-\(.month)-\(.day)"
else .
end;
 
### Mayan Calendar
 
def sacred:
"Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw"
| split(" ");
 
def civil:
"Pop Wo’ Sip Sotz’ Sek Xul Yaxk’in Mol Ch’en Yax Sak’ Keh Mak K’ank’in Muwan’ Pax K’ayab Kumk’u Wayeb’"
| split(" ");
 
def CREATION_TZOLKIN: "2012-12-21";
 
# Input: Date or yyyy-mm-dd
def tzolkin:
(days_between(CREATION_TZOLKIN; yyyymmdd)) as $diff
| {rem: ($diff % 13)}
| if .rem < 0 then .rem += 13 end
| .num = (if .rem <= 9 then .rem + 4 else .rem - 9 end)
| .rem = $diff % 20
| if .rem <= 0 then .rem += 20 end
| [.num, sacred[.rem-1] ] ;
 
# Input: Date or yyyy-mm-dd
def haab:
def ZERO_HAAB: "2019-04-02";
(days_between(ZERO_HAAB; yyyymmdd)) as $diff
| {rem: ($diff % 365)}
| if .rem < 0 then .rem += 365 end
| .month = civil[((.rem+1)/20)|floor]
| .last = (if .month == "Wayeb'" then 5 else 20 end)
| .d = .rem%20 + 1
| if .d < .last then [(.d|tostring), .month]
else ["Chum", .month]
end;
 
# Input: Date or yyyy-mm-dd
def longCount:
{diff: days_between(CREATION_TZOLKIN; yyyymmdd)}
| .diff += 13*400*360
| .baktun = ((.diff/(400*360)) | floor)
| .diff = .diff % (400*360)
| .katun = ((.diff/(20 * 360))|floor)
| .diff = .diff % (20*360)
| .tun = ((.diff/360)|floor)
| .diff = .diff % 360
| .winal = ((.diff/20)|floor)
| .kin = .diff % 20
| [.baktun, .katun, .tun, .winal, .kin]
| join(".");
 
# Input: Date or yyyy-mm-dd
def lord:
{diff: days_between(CREATION_TZOLKIN; yyyymmdd)}
| .rem = .diff % 9
| if .rem <= 0 then .rem += 9 end
| "G\(.rem)";
 
def dates: [
"1961-10-06",
"1963-11-21",
"2004-06-19",
"2012-12-18",
"2012-12-21",
"2019-01-19",
"2019-03-27",
"2020-02-29",
"2020-03-01",
"2071-05-16"
];
 
" Gregorian Tzolk’in Haab’ Long Lord of",
" Date # Name Day Month Count the Night",
"---------- -------- ------------- -------------- ---------",
# Date.default = Date.isoDate
(dates[]
| tzolkin as [$n, $s]
| haab as [$d, $m]
| [., ($n | lpad(4)), ($s | rpad(8)), ($d|lpad(4)), ($m|rpad(8)), (longCount|lpad(20)), (lord|lpad(6))]
| join(" ")
)
</syntaxhighlight>
{{output}}
<pre>
Gregorian Tzolk’in Haab’ Long Lord of
Date # Name Day Month Count the Night
---------- -------- ------------- -------------- ---------
1961-10-06 7 K’ib’ 14 Ch’en 12.17.8.0.16 G7
1963-11-21 3 Eb Chum Keh 12.17.10.3.12 G9
2004-06-19 4 Ben 16 Sotz’ 12.19.11.6.13 G7
2012-12-18 1 Kaban Chum K’ank’in 12.19.19.17.17 G6
2012-12-21 4 Ajaw 3 K’ank’in 13.0.0.0.0 G9
2019-01-19 1 Ajaw 13 Muwan’ 13.0.6.3.0 G6
2019-03-27 3 Manik’ Chum Wayeb’ 13.0.6.6.7 G1
2020-02-29 4 Kimi 14 K’ayab 13.0.7.5.6 G7
2020-03-01 5 Manik’ 15 K’ayab 13.0.7.5.7 G8
2071-05-16 1 Ok 18 Sip 13.2.19.4.10 G9
</pre>
 
=={{header|Julia}}==
{{trans|Go}}
<langsyntaxhighlight lang="julia">using Dates
 
const Tzolk´in = [
Line 556 ⟶ 1,057:
rpad(haab(date), 15), nightlord(date))
end
</syntaxhighlight>
</lang>{{out}}
{{out}}
<pre>
Gregorian Long Count Tzolk´in Haab´ Nightlord
Line 573 ⟶ 1,075:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">sacred = {"Imix\[CloseCurlyQuote]", "Ik\[CloseCurlyQuote]",
"Ak\[CloseCurlyQuote]bal", "K\[CloseCurlyQuote]an", "Chikchan",
"Kimi", "Manik\[CloseCurlyQuote]", "Lamat", "Muluk", "Ok",
Line 639 ⟶ 1,141:
longcountdata = LongCount /@ data;
lotndata = LordOfTheNight /@ data;
{DateObject /@ data, tzolkindata, haabdata, longcountdata, lotndata} // Transpose // Grid</langsyntaxhighlight>
{{out}}
<pre>Sat 19 Jun 2004 4 Ben 16 Sotz' 12.19.11.6.13 G7
Line 652 ⟶ 1,154:
=={{header|Nim}}==
{{trans|Julia}}
<langsyntaxhighlight Nimlang="nim">import math, strformat, times
 
const
Line 715 ⟶ 1,217:
for date in testDates:
let dateStr = date.format("YYYY-MM-dd")
echo &"{dateStr:14} {date.toLongDate:16} {tzolkin(date):9} {haab(date):14} {nightLord(date)}"</langsyntaxhighlight>
 
{{out}}
Line 734 ⟶ 1,236:
The module <code>Math::BaseArith</code> provides mixed-radix conversion via the <code>encode</code> routine (named as in '''APL''').
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use utf8;
Line 812 ⟶ 1,314:
printf "%10s %2s %-9s %4s %-10s %-14s G%d\n",
$date, mayan_calendar_round($date), join('.',mayan_long_count($date)), lord($date);
}</langsyntaxhighlight>
{{out}}
<pre> Gregorian Tzolk’in Haab’ Long Lord of
Line 830 ⟶ 1,332:
=={{header|Phix}}==
{{trans|Go}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
Requires 0.8.1+, or replace the algorithm in timedate.e/timedate_to_julian_day() with the commented-out wikipedia version (jd2).
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<lang Phix>include timedate.e
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
sequence sacred = split("Imix' Ik' Ak'bal K'an Chikchan Kimi Manik' Lamat Muluk Ok Chuwen Eb Ben Hix Men K'ib' Kaban Etz'nab' Kawak Ajaw"),
<span style="color: #004080;">sequence</span> <span style="color: #000000;">sacred</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Imix' Ik' Ak'bal K'an Chikchan Kimi Manik' Lamat Muluk Ok Chuwen Eb Ben Hix Men K'ib' Kaban Etz'nab' Kawak Ajaw"</span><span style="color: #0000FF;">),</span>
civil = split("Pop Wo' Sip Sotz' Sek Xul Yaxk'in Mol Ch'en Yax Sak' Keh Mak K'ank'in Muwan' Pax K'ayab Kumk'u Wayeb'"),
<span style="color: #000000;">civil</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Pop Wo' Sip Sotz' Sek Xul Yaxk'in Mol Ch'en Yax Sak' Keh Mak K'ank'in Muwan' Pax K'ayab Kumk'u Wayeb'"</span><span style="color: #0000FF;">),</span>
date1 = parse_date_string("21/12/2012",{"DD/MM/YYYY"}),
<span style="color: #000000;">date1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"21/12/2012"</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"DD/MM/YYYY"</span><span style="color: #0000FF;">}),</span>
date2 = parse_date_string("2/4/2019",{"DD/MM/YYYY"})
<span style="color: #000000;">date2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"2/4/2019"</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"DD/MM/YYYY"</span><span style="color: #0000FF;">})</span>
 
function tzolkin(integer diff)
<span style="color: #008080;">function</span> <span style="color: #000000;">tzolkin</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">diff</span><span style="color: #0000FF;">)</span>
integer rem = mod(diff,13)
<span style="color: #004080;">integer</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">13</span><span style="color: #0000FF;">)</span>
if rem<0 then rem += 13 end if
<span style="color: #008080;">if</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;"><</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">13</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
integer num = iff(rem<=9?rem+4:rem-9)
<span style="color: #004080;">integer</span> <span style="color: #000000;">num</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rem</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">9</span><span style="color: #0000FF;">?</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">+</span><span style="color: #000000;">4</span><span style="color: #0000FF;">:</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">-</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span>
rem = mod(diff,20)
<span style="color: #000000;">rem</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)</span>
if rem<=0 then rem += 20 end if
<span style="color: #008080;">if</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">20</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
return {num, sacred[rem]}
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">num</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">sacred</span><span style="color: #0000FF;">[</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">]}</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function haab(integer diff)
<span style="color: #008080;">function</span> <span style="color: #000000;">haab</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">diff</span><span style="color: #0000FF;">)</span>
integer rem = mod(diff,365)
<span style="color: #004080;">integer</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">365</span><span style="color: #0000FF;">)</span>
if rem<0 then rem += 365 end if
<span style="color: #008080;">if</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;"><</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">365</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
string month = civil[floor((rem+1)/20)+1]
<span style="color: #004080;">string</span> <span style="color: #000000;">month</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">civil</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
integer last = iff(month="Wayeb'"?5:20),
<span style="color: #004080;">integer</span> <span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">month</span><span style="color: #0000FF;">=</span><span style="color: #008000;">"Wayeb'"</span><span style="color: #0000FF;">?</span><span style="color: #000000;">5</span><span style="color: #0000FF;">:</span><span style="color: #000000;">20</span><span style="color: #0000FF;">),</span>
d = mod(rem,20) + 1
<span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">1</span>
return {iff(d<last?sprintf("%d",d):"Chum"), month}
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;"><</span><span style="color: #000000;">last</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">):</span><span style="color: #008000;">"Chum"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">month</span><span style="color: #0000FF;">}</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function longCount(integer diff)
<span style="color: #008080;">function</span> <span style="color: #000000;">longCount</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">diff</span><span style="color: #0000FF;">)</span>
diff += 13 * 400 * 360
<span style="color: #000000;">diff</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">13</span> <span style="color: #0000FF;">*</span> <span style="color: #000000;">400</span> <span style="color: #0000FF;">*</span> <span style="color: #000000;">360</span>
integer baktun := floor(diff/(400*360))
<span style="color: #004080;">integer</span> <span style="color: #000000;">baktun</span> <span style="color: #0000FF;">:=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">/(</span><span style="color: #000000;">400</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">))</span>
diff = mod(diff,400*360)
<span style="color: #000000;">diff</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">400</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
integer katun := floor(diff/(20*360))
<span style="color: #004080;">integer</span> <span style="color: #000000;">katun</span> <span style="color: #0000FF;">:=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">/(</span><span style="color: #000000;">20</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">))</span>
diff = mod(diff,20*360)
<span style="color: #000000;">diff</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
integer tun = floor(diff/360)
<span style="color: #004080;">integer</span> <span style="color: #000000;">tun</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">/</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
diff = mod(diff,360)
<span style="color: #000000;">diff</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
integer winal = floor(diff/20),
<span style="color: #004080;">integer</span> <span style="color: #000000;">winal</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">/</span><span style="color: #000000;">20</span><span style="color: #0000FF;">),</span>
kin = mod(diff,20)
<span style="color: #000000;">kin</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)</span>
return sprintf("%d.%d.%d.%d.%d", {baktun, katun, tun, winal, kin})
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d.%d.%d.%d.%d"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">baktun</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">katun</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">tun</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">winal</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">kin</span><span style="color: #0000FF;">})</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function lord(integer diff)
<span style="color: #008080;">function</span> <span style="color: #000000;">lord</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">diff</span><span style="color: #0000FF;">)</span>
integer rem = mod(diff,9)
<span style="color: #004080;">integer</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span>
if rem<=0 then rem += 9 end if
<span style="color: #008080;">if</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">rem</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">9</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
return sprintf("G%d", rem)
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"G%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
constant dates = {"1961-10-06",
<span style="color: #008080;">constant</span> <span style="color: #000000;">dates</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"1961-10-06"</span><span style="color: #0000FF;">,</span>
"1963-11-21",
<span style="2004color: #008000;">"1963-0611-1921"</span><span style="color: #0000FF;">,</span>
<span style="2012color: #008000;">"2004-1206-1819"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"2012-12-2118"</span><span style="color: #0000FF;">,</span>
<span style="2019color: #008000;">"2012-0112-1921"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"2019-0301-2719"</span><span style="color: #0000FF;">,</span>
<span style="2020color: #008000;">"2019-0203-2927"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"2020-0302-0129"</span><span style="color: #0000FF;">,</span>
<span style="2071color: #008000;">"2020-0503-1601"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"2071-05-16"</span><span style="color: #0000FF;">,</span>
},
<span style="color: #0000FF;">},</span>
headers = """
<span style="color: #000000;">headers</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Gregorian Tzolk'in Haab' Long Lord of
Gregorian Date Tzolk'in # Name Haab' Day Month Long Count Lord the Nightof
Date # Name Day Month Count the Night
---------- -------- ------------- -------------- ---------
---------- -------- ------------- -------------- ---------
"""
"""</span>
 
procedure main()
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
printf(1,headers)
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">headers</span><span style="color: #0000FF;">)</span>
for i=1 to length(dates) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dates</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
string dt = dates[i]
<span style="color: #004080;">string</span> <span style="color: #000000;">dt</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dates</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
timedate td = parse_date_string(dt,{"YYYY-MM-DD"})
<span style="color: #004080;">timedate</span> <span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">})</span>
integer diff1 = floor(timedate_diff(date1,td,DT_DAY) / (24*60*60)),
<span style="color: #004080;">integer</span> <span style="color: #000000;">diff1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">timedate_diff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">date1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">td</span><span style="color: #0000FF;">,</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">/</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">24</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)),</span>
diff2 = floor(timedate_diff(date2,td,DT_DAY) / (24*60*60))
<span style="color: #000000;">diff2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">timedate_diff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">date2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">td</span><span style="color: #0000FF;">,</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">/</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">24</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">))</span>
{integer n, string s} = tzolkin(diff1)
<span style="color: #0000FF;">{</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tzolkin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff1</span><span style="color: #0000FF;">)</span>
string {d, m} = haab(diff2),
<span style="color: #004080;">string</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">haab</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff2</span><span style="color: #0000FF;">),</span>
lc := longCount(diff1),
<span style="color: #000000;">lc</span> <span style="color: #0000FF;">:=</span> <span style="color: #000000;">longCount</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff1</span><span style="color: #0000FF;">),</span>
l := lord(diff1)
<span style="color: #000000;">l</span> <span style="color: #0000FF;">:=</span> <span style="color: #000000;">lord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">diff1</span><span style="color: #0000FF;">)</span>
printf(1,"%s %2d %-8s %4s %-9s %-14s %s\n", {dt, n, s, d, m, lc, l})
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s %2d %-8s %4s %-9s %-14s %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">dt</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">lc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">})</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end procedure
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
main()</lang>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 922 ⟶ 1,426:
2020-03-01 5 Manik' 15 K'ayab 13.0.7.5.7 G8
2071-05-16 1 Ok 18 Sip 13.2.19.4.10 G9
</pre>
 
=={{header|Python}}==
{{works with|Python|3.6}}
 
<syntaxhighlight lang="python">
import datetime
 
 
def g2m(date, gtm_correlation=True):
"""
Translates Gregorian date into Mayan date, see
https://rosettacode.org/wiki/Mayan_calendar
 
Input arguments:
 
date: string date in ISO-8601 format: YYYY-MM-DD
gtm_correlation: GTM correlation to apply if True, Astronomical correlation otherwise (optional, True by default)
 
Output arguments:
 
long_date: Mayan date in Long Count system as string
round_date: Mayan date in Calendar Round system as string
"""
 
# define some parameters and names
 
correlation = 584283 if gtm_correlation else 584285
 
long_count_days = [144000, 7200, 360, 20, 1]
 
tzolkin_months = ['Imix’', 'Ik’', 'Ak’bal', 'K’an', 'Chikchan', 'Kimi', 'Manik’', 'Lamat', 'Muluk', 'Ok', 'Chuwen',
'Eb', 'Ben', 'Hix', 'Men', 'K’ib’', 'Kaban', 'Etz’nab’', 'Kawak', 'Ajaw'] # tzolk'in
 
haad_months = ['Pop', 'Wo’', 'Sip', 'Sotz’', 'Sek', 'Xul', 'Yaxk’in', 'Mol', 'Ch’en', 'Yax', 'Sak’', 'Keh', 'Mak',
'K’ank’in', 'Muwan', 'Pax', 'K’ayab', 'Kumk’u', 'Wayeb’'] # haab'
 
gregorian_days = datetime.datetime.strptime(date, '%Y-%m-%d').toordinal()
julian_days = gregorian_days + 1721425
 
# 1. calculate long count date
 
long_date = list()
remainder = julian_days - correlation
 
for days in long_count_days:
 
result, remainder = divmod(remainder, days)
long_date.append(int(result))
 
long_date = '.'.join(['{:02d}'.format(d) for d in long_date])
 
# 2. calculate round calendar date
 
tzolkin_month = (julian_days + 16) % 20
tzolkin_day = ((julian_days + 5) % 13) + 1
 
haab_month = int(((julian_days + 65) % 365) / 20)
haab_day = ((julian_days + 65) % 365) % 20
haab_day = haab_day if haab_day else 'Chum'
 
lord_number = (julian_days - correlation) % 9
lord_number = lord_number if lord_number else 9
 
round_date = f'{tzolkin_day} {tzolkin_months[tzolkin_month]} {haab_day} {haad_months[haab_month]} G{lord_number}'
 
return long_date, round_date
 
if __name__ == '__main__':
 
dates = ['2004-06-19', '2012-12-18', '2012-12-21', '2019-01-19', '2019-03-27', '2020-02-29', '2020-03-01']
 
for date in dates:
 
long, round = g2m(date)
print(date, long, round)
</syntaxhighlight>
 
{{out}}
<pre>
2004-06-19 12.19.11.06.13 4 Ben 16 Sotz’ G7
2012-12-18 12.19.19.17.17 1 Kaban Chum K’ank’in G6
2012-12-21 13.00.00.00.00 4 Ajaw 3 K’ank’in G9
2019-01-19 13.00.06.03.00 1 Ajaw 13 Muwan G6
2019-03-27 13.00.06.06.07 3 Manik’ Chum Wayeb’ G1
2020-02-29 13.00.07.05.06 4 Kimi 14 K’ayab G7
2020-03-01 13.00.07.05.07 5 Manik’ 15 K’ayab G8
</pre>
 
Line 928 ⟶ 1,519:
{{works with|Rakudo|2018.12}}
 
<syntaxhighlight lang="raku" perl6line>my @sacred = <Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok
Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw>;
 
Line 999 ⟶ 1,590:
printf "%10s %2s %-9s %4s %-10s %-14s %6s\n", Date.new($date),
flat mayan-calendar-round($date), mayan-long-count($date).join('.'), lord($date);
}</langsyntaxhighlight>
{{out}}
<pre> Gregorian Tzolk’in Haab’ Long Lord of
Line 1,018 ⟶ 1,609:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./date" for Date
import "./fmt" for Fmt
 
var sacred = "Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw".split(" ")
Line 1,097 ⟶ 1,688:
var l = lord.call(date)
Fmt.lprint("$s $2d $-8s $4s $-9s $-14s $s", [dt, n, s, d, m, lc, l])
}</langsyntaxhighlight>
 
{{out}}
Line 1,118 ⟶ 1,709:
=={{header|zkl}}==
{{trans|Go}}
<langsyntaxhighlight lang="zkl">var [const]
sacred=T("Imix'","Ik'","Ak'bal","K'an","Chikchan","Kimi","Manik'","Lamat","Muluk","Ok",
"Chuwen","Eb","Ben","Hix","Men","K'ib'","Kaban","Etz'nab'","Kawak","Ajaw"),
Line 1,166 ⟶ 1,757:
if(rem<=0) rem=9 + rem;
"G%d".fmt(rem)
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println(" Gregorian Tzolk'in Haab' Long Lord of");
println(" Date # Name Day Month Count the Night");
println("---------- -------- ------------- -------------- ---------");
Line 1,183 ⟶ 1,774:
longCount(ymd).concat("."),
lord(ymd)));
});</langsyntaxhighlight>
{{out}}
<pre>