Refactors DateCalculator to be a static class

This change refactors the DateCalculator class to be a static class.
This removes the need to instantiate DateCalculator in multiple
managers and renderers, simplifying dependency management and
ensuring consistent date calculations across the application.
The configuration is now initialized once at the application start.
This commit is contained in:
Janus Knudsen 2025-09-03 18:38:52 +02:00
parent 0da875a224
commit b8b44ddae8
11 changed files with 107 additions and 83 deletions

View file

@ -28,7 +28,10 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
constructor(config: CalendarConfig, dateCalculator?: DateCalculator) {
this.config = config;
this.dateCalculator = dateCalculator || new DateCalculator(config);
if (!dateCalculator) {
DateCalculator.initialize(config);
}
this.dateCalculator = dateCalculator || new DateCalculator();
}
/**
@ -628,7 +631,7 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
private calculateEventGridSpan(event: CalendarEvent, dateToColumnMap: Map<string, number>): { startColumn: number, columnSpan: number } {
const startDate = new Date(event.start);
const endDate = new Date(event.end);
const startDateKey = this.dateCalculator.formatISODate(startDate);
const startDateKey = DateCalculator.formatISODate(startDate);
const startColumn = dateToColumnMap.get(startDateKey);
if (!startColumn) {
@ -641,7 +644,7 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
while (currentDate <= endDate) {
currentDate.setDate(currentDate.getDate() + 1);
const dateKey = this.dateCalculator.formatISODate(currentDate);
const dateKey = DateCalculator.formatISODate(currentDate);
const col = dateToColumnMap.get(dateKey);
if (col) {
endColumn = col;
@ -696,7 +699,7 @@ export class DateEventRenderer extends BaseEventRenderer {
const columnEvents = events.filter(event => {
const eventDate = new Date(event.start);
const eventDateStr = this.dateCalculator.formatISODate(eventDate);
const eventDateStr = DateCalculator.formatISODate(eventDate);
const matches = eventDateStr === columnDate;