Refactors calendar architecture for month view
Prepares the calendar component for month view implementation by introducing a strategy pattern for view management, splitting configuration settings, and consolidating events into a core set. It also removes dead code and enforces type safety, improving overall code quality and maintainability. Addresses critical issues identified in the code review, laying the groundwork for efficient feature addition.
This commit is contained in:
parent
7d513600d8
commit
3ddc6352f2
17 changed files with 1347 additions and 428 deletions
|
|
@ -12,12 +12,26 @@ export class DateCalculator {
|
|||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a date is valid
|
||||
* @param date - Date to validate
|
||||
* @param methodName - Name of calling method for error messages
|
||||
* @throws Error if date is invalid
|
||||
*/
|
||||
private validateDate(date: Date, methodName: string): void {
|
||||
if (!date || !(date instanceof Date) || isNaN(date.getTime())) {
|
||||
throw new Error(`${methodName}: Invalid date provided - ${date}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dates for work week using ISO 8601 day numbering (Monday=1, Sunday=7)
|
||||
* @param weekStart - Any date in the week
|
||||
* @returns Array of dates for the configured work days
|
||||
*/
|
||||
getWorkWeekDates(weekStart: Date): Date[] {
|
||||
this.validateDate(weekStart, 'getWorkWeekDates');
|
||||
|
||||
const dates: Date[] = [];
|
||||
const workWeekSettings = this.config.getWorkWeekSettings();
|
||||
|
||||
|
|
@ -42,6 +56,8 @@ export class DateCalculator {
|
|||
* @returns The Monday of the ISO week
|
||||
*/
|
||||
getISOWeekStart(date: Date): Date {
|
||||
this.validateDate(date, 'getISOWeekStart');
|
||||
|
||||
const monday = new Date(date);
|
||||
const currentDay = monday.getDay();
|
||||
const daysToSubtract = currentDay === 0 ? 6 : currentDay - 1;
|
||||
|
|
@ -57,6 +73,8 @@ export class DateCalculator {
|
|||
* @returns The end date of the ISO week (Sunday)
|
||||
*/
|
||||
getWeekEnd(date: Date): Date {
|
||||
this.validateDate(date, 'getWeekEnd');
|
||||
|
||||
const weekStart = this.getISOWeekStart(date);
|
||||
const weekEnd = new Date(weekStart);
|
||||
weekEnd.setDate(weekStart.getDate() + 6);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue