Add flexible recurring events
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user