108 lines
3.7 KiB
Plaintext
108 lines
3.7 KiB
Plaintext
//=================================================================
|
|
// Convert Gregorian to real Julian Date (not JDE)
|
|
// on entry Gregorian M = month, D = day, Y = YYYY
|
|
// on exit Long JD = Julian Date
|
|
//=================================================================
|
|
|
|
local fn Greg2Julian (M as Int, D as Int, Y as Int) as Long
|
|
Long JD
|
|
JD= D-32075+1461*(Y+4800+(M-14)/12)/4+367*(M-2-(M-14)/12*12)/12-3*((Y+4900+(M-14)/12)/100)/4
|
|
End fn = JD
|
|
|
|
//==================================================================
|
|
// Convert Gregorian to Mayan Calendar
|
|
// on entry Gregorian M = month, D = day, Y = YYYY
|
|
// On exit CFStringRef of Mayan calendar
|
|
//==================================================================
|
|
local fn Greg2Mayan (M as Int, D as Int, Y as Int) as CFStringRef
|
|
|
|
CFStringRef tM(19),hM(18) //Tzolkin and Haad Months
|
|
CFStringRef result
|
|
Long longParts(5)
|
|
Double remainder
|
|
Double JulianDays //Julian Date
|
|
Double LCD(4) //long count days
|
|
Double correlation //Day of creation GTM
|
|
correlation = 584283 //Julian date of Monday 3114 B.C. September 6, @noon
|
|
CFStringRef longDate, roundDate, HaabDay, tmp
|
|
Long tzolkinMonth, tzolkinDay
|
|
Long haabMonth, haabDayNum
|
|
Long lordNumber // Lord of the Nights, nine Deity, God 1 through God 9 (G1 - G9)
|
|
Int i
|
|
|
|
// Sacred Tzolk'in Months, 20 days
|
|
|
|
tM(0) = @"Imix'": tM(1) = @"Ik'": tM(2) = @"Ak'bal": tM(3) = @"K'an"
|
|
tM(4) = @"Chikchan": tM(5) = @"Kimi": tM(6) = @"Manik'": tM(7) = @"Lamat"
|
|
tM(8) = @"Muluk": tM(9) = @"Ok": tM(10) = @"Chuwen": tM(11) = @"Eb"
|
|
tM(12) = @"Ben": tM(13) = @"Hix": tM(14) = @"Men": tM(15) = @"K'ib'"
|
|
tM(16) = @"Kaban": tM(17) = @"Etz'nab'": tM(18) = @"Kawak": tM(19) = @"Ajaw"
|
|
|
|
// Civil Haab Months 20 days
|
|
|
|
hM(0) = @"Pop": hM(1) = @"Wo'": hM(2) = @"Sip": hM(3) = @"Sotz'"
|
|
hM(4) = @"Sek": hM(5) = @"Xul": hM(6) = @"Yaxk'in": hM(7) = @"Mol"
|
|
hM(8) = @"Ch'en": hM(9) = @"Yax": hM(10) = @"Sak'": hM(11) = @"Keh"
|
|
hM(12) = @"Mak": hM(13) = @"K'ank'in": hM(14) = @"Muwan": hM(15) = @"Pax"
|
|
hM(16) = @"K'ayab": hM(17) = @"Kumk'u": hM(18) = @"Wayeb'"
|
|
|
|
// Long count days
|
|
|
|
LCD(0) = 144000: LCD(1) = 7200: LCD(2) = 360: LCD(3) = 20: LCD(4) = 1
|
|
|
|
JulianDays = fn Greg2Julian (M, D, Y)
|
|
remainder = JulianDays - correlation
|
|
For i = 0 To 4
|
|
longParts(i) = Fix(remainder / LCD(i))
|
|
remainder = remainder - (longParts(i) * LCD(i))
|
|
Next i
|
|
|
|
longDate = @""
|
|
For i = 0 To 4
|
|
If i > 0 Then longDate = concat (longDate,@".")
|
|
tmp = mid(str(longParts(i)),1)
|
|
if len(tmp) < 2 then tmp = concat(@"0",tmp)
|
|
longDate = concat(longDate, tmp)
|
|
Next i
|
|
|
|
tzolkinMonth = fix((julianDays + 16) Mod 20)
|
|
tzolkinDay = fix(((julianDays + 5) Mod 13)) + 1
|
|
|
|
haabMonth = fix(((julianDays + 65) Mod 365) / 20)
|
|
haabDayNum = fix(((julianDays + 65) Mod 365) Mod 20)
|
|
|
|
If haabDayNum = 0
|
|
haabDay = @"Chum"
|
|
Else
|
|
haabDay = mid(Str(haabDayNum),1)
|
|
End If
|
|
|
|
lordNumber = Fix((julianDays - correlation) Mod 9)
|
|
If lordNumber = 0 Then lordNumber = 9
|
|
|
|
roundDate = @""
|
|
roundDate = concat(roundDate, @" ", mid(str(tzolkinDay),1), @"\t", tM(tzolkinMonth), @" ", haabDay, @" ", hM(haabMonth), @" G", mid(str(lordNumber),1))
|
|
result = concat(longDate, @" ", roundDate)
|
|
end fn = result
|
|
|
|
Window 1
|
|
|
|
CFStringRef mayanDate, GregDate
|
|
CFArrayRef comps
|
|
Int i,mm,dd,yy
|
|
CFStringRef testDate(7)
|
|
testDate(1) = @"2004-06-19": testDate(2) = @"2012-12-18": testDate(3) = @"2012-12-21": testDate(4) = @"2019-01-19"
|
|
testDate(5) = @"2019-03-27": testDate(6) = @"2020-02-29": testDate(7) = @"2020-03-01"
|
|
|
|
for i = 1 to 7
|
|
GregDate = testDate(i)
|
|
comps = fn StringComponentsSeparatedByString(GregDate, @"-" )
|
|
dd = IntVal(comps[2])
|
|
mm = IntVal(comps[1])
|
|
yy = IntVal(comps[0])
|
|
mayanDate = fn Greg2Mayan (mm,dd,yy)
|
|
print GregDate;" - ";mayanDate
|
|
next i
|
|
|
|
handleEvents
|