Initial commit
This commit is contained in:
96
app/calendar-events.js
Normal file
96
app/calendar-events.js
Normal file
@@ -0,0 +1,96 @@
|
||||
(function () {
|
||||
const {
|
||||
DAY_IN_MS,
|
||||
toTitleCase,
|
||||
getMoonPhaseName,
|
||||
getDecanForDate,
|
||||
calcPlanetaryHoursForDayAndLocation
|
||||
} = window.TarotCalc;
|
||||
|
||||
const PLANET_CALENDAR_IDS = new Set(["saturn", "jupiter", "mars", "sol", "venus", "mercury", "luna"]);
|
||||
const BACKFILL_DAYS = 4;
|
||||
const FORECAST_DAYS = 7;
|
||||
|
||||
function buildWeekEvents(geo, referenceData, anchorDate) {
|
||||
const baseDate = anchorDate || new Date();
|
||||
const events = [];
|
||||
let runningId = 1;
|
||||
|
||||
for (let offset = -BACKFILL_DAYS; offset <= FORECAST_DAYS; offset += 1) {
|
||||
const date = new Date(baseDate.getTime() + offset * DAY_IN_MS);
|
||||
const hours = calcPlanetaryHoursForDayAndLocation(date, geo);
|
||||
const moonIllum = window.SunCalc.getMoonIllumination(date);
|
||||
const moonPhase = getMoonPhaseName(moonIllum.phase);
|
||||
const sunInfo = getDecanForDate(date, referenceData.signs, referenceData.decansBySign);
|
||||
|
||||
const moonTarot = referenceData.planets.luna?.tarot?.majorArcana || "The High Priestess";
|
||||
events.push({
|
||||
id: `moon-${offset}`,
|
||||
calendarId: "astrology",
|
||||
category: "allday",
|
||||
title: `Moon: ${moonPhase} (${Math.round(moonIllum.fraction * 100)}%) · ${moonTarot}`,
|
||||
start: new Date(date.getFullYear(), date.getMonth(), date.getDate()),
|
||||
end: new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59),
|
||||
isReadOnly: true
|
||||
});
|
||||
|
||||
if (sunInfo?.sign) {
|
||||
const rulerPlanet = referenceData.planets[sunInfo.sign.rulingPlanetId];
|
||||
const bodyParts = [
|
||||
`${sunInfo.sign.symbol} ${toTitleCase(sunInfo.sign.element)} ${toTitleCase(sunInfo.sign.modality)}`,
|
||||
rulerPlanet ? `Sign ruler: ${rulerPlanet.symbol} ${rulerPlanet.name}` : `Sign ruler: ${sunInfo.sign.rulingPlanetId}`
|
||||
];
|
||||
|
||||
if (sunInfo.decan) {
|
||||
const decanRuler = referenceData.planets[sunInfo.decan.rulerPlanetId];
|
||||
const decanText = decanRuler
|
||||
? `Decan ${sunInfo.decan.index}: ${sunInfo.decan.tarotMinorArcana} (${decanRuler.symbol} ${decanRuler.name})`
|
||||
: `Decan ${sunInfo.decan.index}: ${sunInfo.decan.tarotMinorArcana}`;
|
||||
bodyParts.unshift(decanText);
|
||||
}
|
||||
|
||||
events.push({
|
||||
id: `sun-${offset}`,
|
||||
calendarId: "astrology",
|
||||
category: "allday",
|
||||
title: `Sun in ${sunInfo.sign.name} · ${sunInfo.sign.tarot.majorArcana}`,
|
||||
body: bodyParts.join("\n"),
|
||||
start: new Date(date.getFullYear(), date.getMonth(), date.getDate()),
|
||||
end: new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59),
|
||||
isReadOnly: true
|
||||
});
|
||||
}
|
||||
|
||||
for (const hour of hours) {
|
||||
const planet = referenceData.planets[hour.planetId];
|
||||
if (!planet) continue;
|
||||
|
||||
const calendarId = PLANET_CALENDAR_IDS.has(hour.planetId)
|
||||
? `planet-${hour.planetId}`
|
||||
: "planetary";
|
||||
|
||||
events.push({
|
||||
id: `ph-${runningId++}`,
|
||||
calendarId,
|
||||
category: "time",
|
||||
title: `${planet.symbol} ${planet.name} · ${planet.tarot.majorArcana}`,
|
||||
body: `${planet.weekday} current · ${hour.isDaylight ? "Day" : "Night"} hour\n${planet.magickTypes}`,
|
||||
raw: {
|
||||
planetSymbol: planet.symbol,
|
||||
planetName: planet.name,
|
||||
tarotName: planet.tarot.majorArcana
|
||||
},
|
||||
start: hour.start,
|
||||
end: hour.end,
|
||||
isReadOnly: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
window.TarotEventBuilder = {
|
||||
buildWeekEvents
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user