summaryrefslogtreecommitdiff
path: root/formats.bqn
blob: 6a3315a33e9fcccdf6cc35790ed44241c9b52046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#
# unix day count
#
MetricDay ⇐ {𝕩⌊∘÷86400.0}

#
# mayan calendar
#
# https://github.com/edgararuiz-zz/maya/tree/master/R
#

## places
baktun       ← 144000
katun        ← 7200
tun          ← 360
winal        ← 20
kin          ← 1

## names
tzolkin_days ← ⟨
	"Ahau"     ⋄ "Imix"  ⋄ "Ik"    ⋄ "Akbal"  ⋄ "Kan"   ⋄
	"Chicchan" ⋄ "Kimi"  ⋄ "Manik" ⋄ "Lamat"  ⋄ "Muluk" ⋄
	"Oc"       ⋄ "Chuen" ⋄ "Eb"    ⋄ "Ben"    ⋄ "Ix"    ⋄
	"Men"      ⋄ "Cib"   ⋄ "Caban" ⋄ "Etznab" ⋄ "Cauac"
⟩
haab_days    ← ⟨
	"Pop" ⋄ "Uo"     ⋄ "Zip"   ⋄ "Zotz"   ⋄ "Zec"  ⋄
	"Xul" ⋄ "Yaxkin" ⋄ "Mol"   ⋄ "Chen"   ⋄ "Yax"  ⋄
	"Sac" ⋄ "Ceh"    ⋄ "Mac"   ⋄ "Kankin" ⋄ "Muan" ⋄
	"Pax" ⋄ "Kayab"  ⋄ "Cumku" ⋄ "Wayeb"
⟩
lords_of_the_night ← ⟨
	"(1a) Tlaloc"          ⋄ "(1b) Tepeyollotl"     ⋄ "(1c) Tlazolteotl" ⋄
	"(2a) Centeotl"        ⋄ "(2b) Mictlantecuhtli" ⋄ "(2c) Chalchiuhtlicue" ⋄
	"(3a) Piltzintecuhtli" ⋄ "(3b) Tezcatlipoca"    ⋄ "(3c) Xiuhtecuhtli"
⟩
## numbers
mayan_numerals ⇐ {@-𝕩}¨-(-˝(↕20)≍20/⟨¯119520⟩)
FormatSeries ← {
	#  Y_B
	# ba ka
	# tu wi
	# ki tz
	# ha ln
	3‿2 ⥊ { 𝕩⊑mayan_numerals }¨𝕩
}

UnixToMayanDay ⇐ {
	UnixToJulianDay ← { 2440587.5+𝕩÷86400.0 }
	UnixToMaya      ← { ⌊584283-˜UnixToJulianDay 𝕩 }
	LongCount       ← {
		# FIXME missing day
		Sc ← { +´×˝(baktun‿katun‿tun‿winal‿kin≍𝕩) }
		ba ← baktun ⌊∘÷˜ 𝕩
		ka ← katun  ⌊∘÷˜ 𝕩-Sc ba‿0‿0‿0‿0
		tu ← tun    ⌊∘÷˜ 𝕩-Sc ba‿ka‿0‿0‿0
		wi ← winal  ⌊∘÷˜ 𝕩-Sc ba‿ka‿tu‿0‿0
		ki ← kin    ⌊∘÷˜ 𝕩-Sc ba‿ka‿tu‿wi‿0
		ba‿ka‿tu‿wi‿ki
	}
	s ← UnixToMaya 𝕩
	c ← LongCount s
	s‿c
}
MayanDate ⇐ { ## full date, including supplemental series
	Tzolkin ← {
		d       ← 𝕩-260×𝕩⌊∘÷260
		radical ← 4+d-13×13⌊∘÷˜d+3
		kin     ← ⌊d-winal×d⌊∘÷winal
		radical‿kin
	}
	Haabkin ← {
		d       ← 𝕩+348-365×365⌊∘÷˜𝕩+348
		radical ← d-winal×d⌊∘÷winal
		kin     ← d⌊∘÷winal
		radical‿kin
	}
	YearBearer ← {
		Ybkin                    ← { 0≤˜winal|˜𝕨-𝕩 }◶{ winal|˜𝕨-𝕩 }‿{ winal|˜𝕨-𝕩+winal }
		⟨ t ⋄ h ⟩                ← 𝕩
		⟨tzol_radical ⋄ tzolkin⟩ ← t
		⟨haab_radical ⋄ haabkin⟩ ← h
		radical                  ← {𝕩≤0}◶{𝕩}‿{𝕩+13} tzol_radical-haab_radical-haabkin×7
		kin                      ← 1+tzolkin Ybkin haab_radical
		radical‿kin
	}
	LordOfNight ← {
		⟨ba, ka, tu, wi, ki⟩ ← 𝕩×baktun‿katun‿tun‿winal‿kin
		lon                  ← 1+9|wi+ki+8
		lon
	}
	FName ← { ⟨r, kin⟩ ← 𝕩 ⋄ r‿(kin⊑𝕨) }

	⟨ s ⋄ c ⟩ ← UnixToMayanDay 𝕩
	t ← Tzolkin s
	h ← Haabkin s

	⟨
		tzolkin_days FName YearBearer t‿h ⋄ c ⋄
		tzolkin_days FName t ⋄ haab_days FName h ⋄
		LordOfNight c
	⟩
}
# vi: ts=2