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:
parent
0da875a224
commit
b8b44ddae8
11 changed files with 107 additions and 83 deletions
|
|
@ -24,7 +24,8 @@ export class NavigationRenderer {
|
|||
this.eventBus = eventBus;
|
||||
this.config = config;
|
||||
this.eventRenderer = eventRenderer;
|
||||
this.dateCalculator = new DateCalculator(config);
|
||||
DateCalculator.initialize(config);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +128,7 @@ export class NavigationRenderer {
|
|||
* Render a complete container with content and events
|
||||
*/
|
||||
public renderContainer(parentContainer: HTMLElement, weekStart: Date): HTMLElement {
|
||||
const weekEnd = this.dateCalculator.addDays(weekStart, 6);
|
||||
const weekEnd = DateCalculator.addDays(weekStart, 6);
|
||||
|
||||
|
||||
// Create new grid container
|
||||
|
|
@ -179,22 +180,22 @@ export class NavigationRenderer {
|
|||
dayColumns.innerHTML = '';
|
||||
|
||||
// Get dates using DateCalculator
|
||||
const dates = this.dateCalculator.getWorkWeekDates(weekStart);
|
||||
const dates = DateCalculator.getWorkWeekDates(weekStart);
|
||||
|
||||
// Render headers for target week
|
||||
dates.forEach((date, i) => {
|
||||
const headerElement = document.createElement('swp-day-header');
|
||||
if (this.dateCalculator.isToday(date)) {
|
||||
if (DateCalculator.isToday(date)) {
|
||||
headerElement.dataset.today = 'true';
|
||||
}
|
||||
|
||||
const dayName = this.dateCalculator.getDayName(date, 'short');
|
||||
const dayName = DateCalculator.getDayName(date, 'short');
|
||||
|
||||
headerElement.innerHTML = `
|
||||
<swp-day-name>${dayName}</swp-day-name>
|
||||
<swp-day-date>${date.getDate()}</swp-day-date>
|
||||
`;
|
||||
headerElement.dataset.date = this.dateCalculator.formatISODate(date);
|
||||
headerElement.dataset.date = DateCalculator.formatISODate(date);
|
||||
|
||||
header.appendChild(headerElement);
|
||||
});
|
||||
|
|
@ -209,7 +210,7 @@ export class NavigationRenderer {
|
|||
// Render day columns for target week
|
||||
dates.forEach(date => {
|
||||
const column = document.createElement('swp-day-column');
|
||||
column.dataset.date = this.dateCalculator.formatISODate(date);
|
||||
column.dataset.date = DateCalculator.formatISODate(date);
|
||||
|
||||
const eventsLayer = document.createElement('swp-events-layer');
|
||||
column.appendChild(eventsLayer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue