Jump to content

Mayan calendar: Difference between revisions

m (→‎{{header|Wren}}: Minor tidy)
 
Line 864:
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>
 
Line 921 ⟶ 1,057:
rpad(haab(date), 15), nightlord(date))
end
</syntaxhighlight>{{out}}
{{out}}
<pre>
Gregorian Long Count Tzolk´in Haab´ Nightlord
2,484

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.