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
|
|
@ -15,7 +15,8 @@ export class WeekViewStrategy implements ViewStrategy {
|
|||
private styleManager: GridStyleManager;
|
||||
|
||||
constructor() {
|
||||
this.dateCalculator = new DateCalculator(calendarConfig);
|
||||
DateCalculator.initialize(calendarConfig);
|
||||
this.dateCalculator = new DateCalculator();
|
||||
this.gridRenderer = new GridRenderer(calendarConfig);
|
||||
this.styleManager = new GridStyleManager(calendarConfig);
|
||||
}
|
||||
|
|
@ -42,28 +43,28 @@ export class WeekViewStrategy implements ViewStrategy {
|
|||
}
|
||||
|
||||
getNextPeriod(currentDate: Date): Date {
|
||||
return this.dateCalculator.addWeeks(currentDate, 1);
|
||||
return DateCalculator.addWeeks(currentDate, 1);
|
||||
}
|
||||
|
||||
getPreviousPeriod(currentDate: Date): Date {
|
||||
return this.dateCalculator.addWeeks(currentDate, -1);
|
||||
return DateCalculator.addWeeks(currentDate, -1);
|
||||
}
|
||||
|
||||
getPeriodLabel(date: Date): string {
|
||||
const weekStart = this.dateCalculator.getISOWeekStart(date);
|
||||
const weekEnd = this.dateCalculator.addDays(weekStart, 6);
|
||||
const weekNumber = this.dateCalculator.getWeekNumber(date);
|
||||
const weekStart = DateCalculator.getISOWeekStart(date);
|
||||
const weekEnd = DateCalculator.addDays(weekStart, 6);
|
||||
const weekNumber = DateCalculator.getWeekNumber(date);
|
||||
|
||||
return `Week ${weekNumber}: ${this.dateCalculator.formatDateRange(weekStart, weekEnd)}`;
|
||||
return `Week ${weekNumber}: ${DateCalculator.formatDateRange(weekStart, weekEnd)}`;
|
||||
}
|
||||
|
||||
getDisplayDates(baseDate: Date): Date[] {
|
||||
return this.dateCalculator.getWorkWeekDates(baseDate);
|
||||
return DateCalculator.getWorkWeekDates(baseDate);
|
||||
}
|
||||
|
||||
getPeriodRange(baseDate: Date): { startDate: Date; endDate: Date } {
|
||||
const weekStart = this.dateCalculator.getISOWeekStart(baseDate);
|
||||
const weekEnd = this.dateCalculator.addDays(weekStart, 6);
|
||||
const weekStart = DateCalculator.getISOWeekStart(baseDate);
|
||||
const weekEnd = DateCalculator.addDays(weekStart, 6);
|
||||
|
||||
return {
|
||||
startDate: weekStart,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue