Refactors date handling for ISO week compatibility

Centralizes all date calculations into a new `DateCalculator` class for better maintainability and consistency.

Ensures correct ISO week handling (Monday as the first day) throughout the calendar.

Updates `CalendarConfig` to use ISO day numbering (1-7 for Mon-Sun) for work week definitions.

Fixes issue where date calculations were inconsistent.
Enhances event rendering and navigation.
Updates navigation logic to use pre-rendered events.
Removes the need for `CONTAINER_READY_FOR_EVENTS` event.
This commit is contained in:
Janus Knudsen 2025-08-20 00:39:31 +02:00
parent efc1742dad
commit 7d513600d8
13 changed files with 230 additions and 343 deletions

View file

@ -4,7 +4,6 @@ import { eventBus } from '../core/EventBus';
import { calendarConfig } from '../core/CalendarConfig';
import { EventTypes } from '../constants/EventTypes';
import { StateEvents } from '../types/CalendarState';
import { DateUtils } from '../utils/DateUtils';
import { DateCalculator } from '../utils/DateCalculator';
import { ResourceCalendarData } from '../types/CalendarTypes';
import { GridRenderer } from '../renderers/GridRenderer';
@ -105,6 +104,7 @@ export class GridManager {
this.render();
});
// Handle events loaded
eventBus.on(EventTypes.EVENTS_LOADED, (e: Event) => {
const detail = (e as CustomEvent).detail;
@ -147,12 +147,14 @@ export class GridManager {
}
}
console.log('GridManager: Starting render with grid element:', this.grid);
console.group(`🏗️ GRID RENDER: ${this.currentWeek?.toDateString()}`);
console.log('Updating grid styles and rendering structure...');
this.styleManager.updateGridStyles(this.resourceData);
this.gridRenderer.renderGrid(this.grid, this.currentWeek!, this.resourceData, this.allDayEvents);
const columnCount = this.styleManager.getColumnCount(this.resourceData);
console.log(`GridManager: Render complete - created ${columnCount} columns`);
console.log(`Grid structure complete - ${columnCount} columns created`);
// Emit GRID_RENDERED event to trigger event rendering
const weekEnd = this.currentWeek ? new Date(this.currentWeek.getTime() + 6 * 24 * 60 * 60 * 1000) : null;
@ -163,6 +165,8 @@ export class GridManager {
endDate: weekEnd,
columnCount: columnCount
});
console.groupEnd();
}
// Column count calculation moved to GridStyleManager