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
|
|
@ -41,7 +41,8 @@ export class CalendarManager {
|
|||
this.eventRenderer = eventRenderer;
|
||||
this.scrollManager = scrollManager;
|
||||
this.eventFilterManager = new EventFilterManager();
|
||||
this.dateCalculator = new DateCalculator(config);
|
||||
DateCalculator.initialize(config);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
|
|
@ -434,10 +435,10 @@ export class CalendarManager {
|
|||
const lastDate = new Date(lastDateStr);
|
||||
|
||||
// Calculate week number from first date
|
||||
const weekNumber = this.dateCalculator.getWeekNumber(firstDate);
|
||||
const weekNumber = DateCalculator.getWeekNumber(firstDate);
|
||||
|
||||
// Format date range
|
||||
const dateRange = this.dateCalculator.formatDateRange(firstDate, lastDate);
|
||||
const dateRange = DateCalculator.formatDateRange(firstDate, lastDate);
|
||||
|
||||
// Emit week info update
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ export class NavigationManager {
|
|||
|
||||
constructor(eventBus: IEventBus, eventRenderer: EventRenderingService) {
|
||||
this.eventBus = eventBus;
|
||||
this.dateCalculator = new DateCalculator(calendarConfig);
|
||||
DateCalculator.initialize(calendarConfig);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
this.navigationRenderer = new NavigationRenderer(eventBus, calendarConfig, eventRenderer);
|
||||
this.currentWeek = this.dateCalculator.getISOWeekStart(new Date());
|
||||
this.currentWeek = DateCalculator.getISOWeekStart(new Date());
|
||||
this.targetWeek = new Date(this.currentWeek);
|
||||
this.init();
|
||||
}
|
||||
|
|
@ -135,7 +136,7 @@ export class NavigationManager {
|
|||
|
||||
private navigateToToday(): void {
|
||||
const today = new Date();
|
||||
const todayWeekStart = this.dateCalculator.getISOWeekStart(today);
|
||||
const todayWeekStart = DateCalculator.getISOWeekStart(today);
|
||||
|
||||
// Reset to today
|
||||
this.targetWeek = new Date(todayWeekStart);
|
||||
|
|
@ -153,7 +154,7 @@ export class NavigationManager {
|
|||
}
|
||||
|
||||
private navigateToDate(date: Date): void {
|
||||
const weekStart = this.dateCalculator.getISOWeekStart(date);
|
||||
const weekStart = DateCalculator.getISOWeekStart(date);
|
||||
this.targetWeek = new Date(weekStart);
|
||||
|
||||
const currentTime = this.currentWeek.getTime();
|
||||
|
|
@ -247,9 +248,9 @@ export class NavigationManager {
|
|||
}
|
||||
|
||||
private updateWeekInfo(): void {
|
||||
const weekNumber = this.dateCalculator.getWeekNumber(this.currentWeek);
|
||||
const weekEnd = this.dateCalculator.addDays(this.currentWeek, 6);
|
||||
const dateRange = this.dateCalculator.formatDateRange(this.currentWeek, weekEnd);
|
||||
const weekNumber = DateCalculator.getWeekNumber(this.currentWeek);
|
||||
const weekEnd = DateCalculator.addDays(this.currentWeek, 6);
|
||||
const dateRange = DateCalculator.formatDateRange(this.currentWeek, weekEnd);
|
||||
|
||||
// Notify other managers about week info update - DOM manipulation should happen via events
|
||||
this.eventBus.emit(CoreEvents.WEEK_CHANGED, {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ export class WorkHoursManager {
|
|||
|
||||
constructor(config: CalendarConfig) {
|
||||
this.config = config;
|
||||
this.dateCalculator = new DateCalculator(config);
|
||||
DateCalculator.initialize(config);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
|
||||
// Default work schedule - will be loaded from JSON later
|
||||
this.workSchedule = {
|
||||
|
|
@ -64,7 +65,7 @@ export class WorkHoursManager {
|
|||
* Get work hours for a specific date
|
||||
*/
|
||||
getWorkHoursForDate(date: Date): DayWorkHours | 'off' {
|
||||
const dateString = this.dateCalculator.formatISODate(date);
|
||||
const dateString = DateCalculator.formatISODate(date);
|
||||
|
||||
// Check for date-specific override first
|
||||
if (this.workSchedule.dateOverrides[dateString]) {
|
||||
|
|
@ -83,7 +84,7 @@ export class WorkHoursManager {
|
|||
const workHoursMap = new Map<string, DayWorkHours | 'off'>();
|
||||
|
||||
dates.forEach(date => {
|
||||
const dateString = this.dateCalculator.formatISODate(date);
|
||||
const dateString = DateCalculator.formatISODate(date);
|
||||
const workHours = this.getWorkHoursForDate(date);
|
||||
workHoursMap.set(dateString, workHours);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue