Add flexible recurring events

This commit is contained in:
Kiyomichi Kosaka
2025-06-20 00:26:11 +02:00
parent d11b8cf19f
commit 5e703813d7
2 changed files with 43 additions and 16 deletions
+25 -6
View File
@@ -613,13 +613,32 @@ function updateCalendar() {
</div>`;
if (Array.isArray(window.SPECIAL_EVENTS)) {
const offsetStart = ((cellCob % COBIE_UNITS.cosmocycle) + COBIE_UNITS.cosmocycle) % COBIE_UNITS.cosmocycle;
const offsetEnd = offsetStart + COBIE_UNITS.eonstrip;
const cellStart = cellCob;
const cellEnd = cellCob + COBIE_UNITS.eonstrip;
window.SPECIAL_EVENTS.forEach(ev => {
const evCob = parseCobiets(ev.cobie);
if (evCob === null) return;
const evOffset = ((evCob % COBIE_UNITS.cosmocycle) + COBIE_UNITS.cosmocycle) % COBIE_UNITS.cosmocycle;
if (evOffset >= offsetStart && evOffset < offsetEnd) {
const startCob = parseCobiets(ev.start || ev.cobie);
if (startCob === null) return;
const endCob = ev.end ? parseCobiets(ev.end) : Number.POSITIVE_INFINITY;
const unitVal = COBIE_UNITS[ev.unit] || COBIE_UNITS.cosmocycle;
const interval = (ev.interval || 1) * unitVal;
let duration = 0;
if (typeof ev.duration === 'string') {
const d = parseCobiets(ev.duration);
if (d !== null) duration = d;
} else if (typeof ev.duration === 'number') {
duration = ev.duration;
}
if (cellStart > endCob) return;
let n = Math.floor((cellStart - startCob) / interval);
if (n < 0) n = 0;
let occ = startCob + n * interval;
if (occ + duration <= cellStart) {
occ += interval;
}
if (occ < cellEnd && occ + duration > cellStart && occ <= endCob) {
const tag = document.createElement('div');
tag.className = 'event-tag';
tag.textContent = ev.label;