Mayan calendar: Difference between revisions
Content deleted Content added
No edit summary |
|||
(25 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">
PROGRAM MAYA_DRIVER
IMPLICIT NONE
!
! Local variables
!
CHARACTER(80) :: haab_carry
CHARACTER(80) :: long_carry
CHARACTER(80) :: nightlord
CHARACTER(80) :: tzolkin_carry
INTEGER,DIMENSION(8) :: DAY, MONTH, YEAR
INTEGER :: INDEX
DATA YEAR /2071,2004,2012,2012,2019,2019,2020,2020/
DATA MONTH /5,6,12,12,1,3,2,3/
DATA DAY /16,19,18,21,19,27,29,01/
! 2071-05-16
! 2004-06-19
! 2012-12-18
! 2012-12-21
! 2019-01-19
! 2019-03-27
! 2020-02-29
! 2020-03-01
DO INDEX = 1,8
!
CALL MAYA_TIME(day(INDEX) , month(INDEX) , year(INDEX) , long_carry , haab_carry , tzolkin_carry , &
& nightlord)
WRITE(6,20)day(INDEX),month(INDEX),year(INDEX),TRIM(tzolkin_carry),TRIM(haab_carry),TRIM(long_carry),TRIM(nightlord)
20 FORMAT(1X,I0,'-',I0,'-',I0,T12,A,T24,A,T38,A,T58,A)
END DO
STOP
END PROGRAM MAYA_DRIVER
!
! SUBROUTINE MAYA_TIME
subroutine maya_time(day,month,year, long_carry,haab_carry, tzolkin_carry,nightlord)
implicit none
integer(kind=4), parameter :: startdate = 584283 ! Start of the Mayan Calendar in Julian days
integer(kind=4), parameter :: kin = 1
integer(kind=4), parameter :: winal = 20*kin
integer(kind=4), parameter :: tun = winal*18
integer(kind=4), parameter :: katun = tun*20
integer(kind=4), parameter :: baktun = katun*20
integer(kind=4), parameter :: piktun = baktun*20
integer(kind=4), parameter :: longcount = baktun*20
!
character(len=8), dimension(20) ,parameter :: 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 "]
character(len=8), dimension(19) ,parameter :: 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´ "]
character(len=20), dimension(9) ,parameter :: night_lords = &
["(G1) Xiuhtecuhtli ", & ! ("Turquoise/Year/Fire Lord")
"(G2) Tezcatlipoca ", & ! ("Smoking Mirror")
"(G3) Piltzintecuhtli", & ! ("Prince Lord")
"(G4) Centeotl ", & ! ("Maize God")
"(G5) Mictlantecuhtli", & ! ("Underworld Lord")
"(G6) Chalchiuhtlicue", & ! ("Jade Is Her Skirt")
"(G7) Tlazolteotl ", & ! ("Filth God[dess]")
"(G8) Tepeyollotl ", & ! ("Mountain Heart")
"(G9) Tlaloc " ] ! (Rain God)
integer(kind=4) :: day,month,year
intent(in) :: day,month,year
!
integer(kind=4) :: j,l, numdays, keptdays
integer(kind=4) :: kin_no, winal_no, tun_no, katun_no, baktun_no, longcount_no
character(*) :: haab_carry, nightlord, tzolkin_carry, long_carry
intent(inout) :: haab_carry, nightlord, tzolkin_carry, long_carry
integer :: mo,da
!
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
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
print*, ' We have more than one longcount ',longcount_no
endif
!
! Calculate the longdate
baktun_no = numdays/baktun
numdays = numdays - (baktun_no*baktun) ! Decrement days down by the number of baktuns
katun_no = numdays/katun ! Get number of katuns
numdays = numdays - (katun_no*katun)
tun_no = numdays/tun
numdays = numdays-(tun_no*tun)
winal_no = numdays/winal
numdays = numdays-(winal_no*winal)
kin_no = numdays ! What is left is simply the days
long_carry = ' ' ! blank it out
write(long_carry,'(4(i2.2,"."),I2.2)') baktun_no,katun_no,tun_no,winal_no,kin_no
!
! OK. Now the longcount is done, let's calculate Tzolk´in, Haab´ & Nightlord (the calendar round)
!
haab_carry = " "
L = mod((keptdays+65),365)
mo = (L/20)+1
da = mod(l,20)
if(da.ne.0)then
write(haab_carry,'(i2,1x,a)') da,haab(mo)
else
write(haab_carry,'(a,1x,a)') 'Chum',haab(mo)
endif
!
! Ok, Now let's calculate the Tzolk´in
! The calendar starts on the 4 Ahu
tzolkin_carry = " " ! Total blank the carrier
mo = mod((keptdays+16),20) + 1
da = mod((keptdays+5),13) + 1
write(tzolkin_carry,'(i2,1x,a)') da,tzolkin(mo)
!
! Now let's have a look at the lords of the night
! There are 9 lords of the night, let's assume that they start on the first day of the year
!
numdays = keptdays -startdate ! Elapsed Julian days since start of calendar
J = mod(numdays,9) ! Number of days into this cycle
if (j.eq.0) j = 9
nightlord = night_lords(j)
RETURN
contains
!
FUNCTION JULDAY( Id , Mm, Iyyy)
IMPLICIT NONE
!
! PARAMETER definitions
!
INTEGER , PARAMETER :: IGREG = 15 + 31*(10 + 12*1582)
!
! Dummy arguments
!
INTEGER :: Id , Iyyy , Mm
INTEGER :: JULDAY
INTENT (IN) Id , Iyyy , Mm
!
! Local variables
!
INTEGER :: ja , jm , jy
!
jy = Iyyy
IF(jy == 0)STOP 'julday: there is no year zero'
IF(jy < 0)jy = jy + 1
IF(Mm > 2)THEN
jm = Mm + 1
ELSE
jy = jy - 1
jm = Mm + 13
END IF
JULDAY = 365*jy + INT(0.25D0*jy + 2000.D0) + INT(30.6001D0*jm) + Id + 1718995
IF(Id + 31*(Mm + 12*Iyyy) >= IGREG)THEN
ja = INT(0.01D0*jy)
JULDAY = JULDAY + 2 - ja + INT(0.25D0*ja)
END IF
RETURN
END FUNCTION JULDAY
END SUBROUTINE maya_time
</syntaxhighlight>
{{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}}==
<syntaxhighlight lang="go">package main
import (
Line 318 ⟶ 683:
fmt.Printf("%s %2d %-8s %4s %-9s %-14s %s\n", dt, n, s, d, m, lc, l)
}
}</
{{out}}
Line 333 ⟶ 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}}
<
const Tzolk´in = [
Line 390 ⟶ 1,057:
rpad(haab(date), 15), nightlord(date))
end
</syntaxhighlight>
{{out}}
<pre>
Gregorian Long Count Tzolk´in Haab´ Nightlord
Line 407 ⟶ 1,075:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
"Ak\[CloseCurlyQuote]bal", "K\[CloseCurlyQuote]an", "Chikchan",
"Kimi", "Manik\[CloseCurlyQuote]", "Lamat", "Muluk", "Ok",
Line 473 ⟶ 1,141:
longcountdata = LongCount /@ data;
lotndata = LordOfTheNight /@ data;
{DateObject /@ data, tzolkindata, haabdata, longcountdata, lotndata} // Transpose // Grid</
{{out}}
<pre>Sat 19 Jun 2004 4 Ben 16 Sotz' 12.19.11.6.13 G7
Line 486 ⟶ 1,154:
=={{header|Nim}}==
{{trans|Julia}}
<
const
Line 549 ⟶ 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)}"</
{{out}}
Line 568 ⟶ 1,236:
The module <code>Math::BaseArith</code> provides mixed-radix conversion via the <code>encode</code> routine (named as in '''APL''').
{{trans|Raku}}
<
use warnings;
use utf8;
Line 646 ⟶ 1,314:
printf "%10s %2s %-9s %4s %-10s %-14s G%d\n",
$date, mayan_calendar_round($date), join('.',mayan_long_count($date)), lord($date);
}</
{{out}}
<pre> Gregorian Tzolk’in Haab’ Long Lord of
Line 664 ⟶ 1,332:
=={{header|Phix}}==
{{trans|Go}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<span style="
<span style="
<span style="color: #008000;">"2012-12-
<span style="
<span style="color: #008000;">"2019-
<span style="
<span style="color: #008000;">"2020-
<span style="
<span style="color: #008000;">"2071-05-16"</span><span style="color: #0000FF;">,</span>
<span style="color: #0000FF;">},</span>
<span style="color: #000000;">headers</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Gregorian
Date # Name Day Month Count the Night
---------- -------- ------------- -------------- ---------
"""</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 756 ⟶ 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 762 ⟶ 1,519:
{{works with|Rakudo|2018.12}}
<syntaxhighlight lang="raku"
Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw>;
Line 833 ⟶ 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);
}</
{{out}}
<pre> Gregorian Tzolk’in Haab’ Long Lord of
Line 852 ⟶ 1,609:
{{libheader|Wren-date}}
{{libheader|Wren-fmt}}
<
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 931 ⟶ 1,688:
var l = lord.call(date)
Fmt.lprint("$s $2d $-8s $4s $-9s $-14s $s", [dt, n, s, d, m, lc, l])
}</
{{out}}
Line 952 ⟶ 1,709:
=={{header|zkl}}==
{{trans|Go}}
<
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,000 ⟶ 1,757:
if(rem<=0) rem=9 + rem;
"G%d".fmt(rem)
}</
<
println(" Date # Name Day Month Count the Night");
println("---------- -------- ------------- -------------- ---------");
Line 1,017 ⟶ 1,774:
longCount(ymd).concat("."),
lord(ymd)));
});</
{{out}}
<pre>
|