LOADING
// -- get today --
// Begin the application with today's date
var d = new Date();
var day = parseInt(d.getDate());
var month = 1+parseInt(d.getMonth());
var year = parseInt(d.getUTCFullYear());
// -- fixed start vars --
// We start using a fixed date, in this case 21/12/2012
var StartValues = Array(
21, // 0) day
12, // 1) month
2012, // 2) year
207, // 3) kin(260)
3, // 4) color(4)
12, // 5) tone(13)
7, // 6) seal(20)
112 // 7) year(#nr)
);
// --- KIN Calculation ---
// THE function that calculates color, tone, seal & kin.
function getTzolkinInfo(){
// [1] Copy the start values into a new array
var Ret = StartValues.slice(0, StartValues.length+1);
// [2] Create a timestamp from the fixed date
var fix_tm = mktime(Ret[2],Ret[1],Ret[0]);
// [3] Create a timestamp from the input date
var now_tm = mktime(year,month,day);
// [4] Loop to get the month & year #nr
if (fix_tm > now_tm) {
// Get the year#nr in the past.
while (Ret[2] != year) {
Ret[2]--;
// minus 105 each loop.
Ret[7]-=105;
// if lower than 1, plus 260
if (Ret[7]<1) { Ret[7]+=260; }
}
// Get the month#nr in the past.
while (Ret[1] != month) {
Ret[1]--;
if (Ret[1]<1) { Ret[1]+=12; }
}
} else if(now_tm > fix_tm) {
// Get the year#nr in the future.
while (Ret[2] != year) {
Ret[2]++;
// add 105 each loop.
Ret[7]+=105;
// if higher than 260, minus 260
if (Ret[7]>260) { Ret[7]-=260; }
}
// Get the month#nr in the future.
while (Ret[1] != month) {
Ret[1]++;
if (Ret[1]>12) { Ret[1]-=12; }
}
}
// [5] KIN = day#nr + month#nr + year#nr
Ret[3] = day + monD[Ret[1]-1] + Ret[7];
// if higher than 260, minus 260
while (Ret[3] > 260) { Ret[3] -= 260; }
// set "var kin" to fixed kin
var kin = StartValues[3];
// [6] Get color, tone & seal
if ( kin > Ret[3] ) { // -- count down
while ( kin > Ret[3] ) {
kin--;
// color-1 (if lower than 1, add 4)
Ret[4]--; if (Ret[4]<1) {Ret[4]+=4;}
// tone-1 (if lower than 1, add 13)
Ret[5]--; if (Ret[5]<1) {Ret[5]+=13;}
// seal-1 (if lower than 1, add 20)
Ret[6]--; if (Ret[6]<1) {Ret[6]+=20;}
}
} else { // -- count up
while ( kin < Ret[3] ) {
kin++;
// color+1 (if higher than 4, min 4)
Ret[4]++; if (Ret[4]>4) {Ret[4]-=4;}
// tone+1 (if higher than 13, min 13)
Ret[5]++; if (Ret[5]>13) {Ret[5]-=13;}
// seal+1 (if higher than 20, min 20)
Ret[6]++; if (Ret[6]>20) {Ret[6]-=20;}
}
}
// [7] Array "Ret" has now all info...
// Ret = (day,month,year,kin,color,tone,seal,year)
writeTzolkinResult(Ret); // -- Return Array [Ret]
}
// --> Check out this source for more details! ------
// ----------------------------------------------------
// -- for more info contact tGWdb via myTzolkin.com ---
|
tGWdb scripts 2008