Refactors date handling to use DateService
Standardizes date manipulation across the application by leveraging the DateService. This change improves consistency and reduces code duplication by removing redundant date calculations.
This commit is contained in:
parent
6bbf2d8adb
commit
a86a736340
6 changed files with 69 additions and 77 deletions
|
|
@ -98,19 +98,21 @@ export class MonthViewStrategy implements ViewStrategy {
|
|||
}
|
||||
|
||||
private getMonthDates(monthDate: Date): Date[] {
|
||||
// Get first day of month
|
||||
const firstOfMonth = new Date(monthDate.getFullYear(), monthDate.getMonth(), 1);
|
||||
|
||||
// Get first day of month using DateService
|
||||
const year = monthDate.getFullYear();
|
||||
const month = monthDate.getMonth();
|
||||
const firstOfMonth = this.dateService.startOfDay(new Date(year, month, 1));
|
||||
|
||||
// Get Monday of the week containing first day
|
||||
const weekBounds = this.dateService.getWeekBounds(firstOfMonth);
|
||||
const startDate = this.dateService.startOfDay(weekBounds.start);
|
||||
|
||||
|
||||
// Generate 42 days (6 weeks)
|
||||
const dates: Date[] = [];
|
||||
for (let i = 0; i < 42; i++) {
|
||||
dates.push(this.dateService.addDays(startDate, i));
|
||||
}
|
||||
|
||||
|
||||
return dates;
|
||||
}
|
||||
|
||||
|
|
@ -120,11 +122,17 @@ export class MonthViewStrategy implements ViewStrategy {
|
|||
}
|
||||
|
||||
getNextPeriod(currentDate: Date): Date {
|
||||
return new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1);
|
||||
const nextMonth = this.dateService.addMonths(currentDate, 1);
|
||||
const year = nextMonth.getFullYear();
|
||||
const month = nextMonth.getMonth();
|
||||
return this.dateService.startOfDay(new Date(year, month, 1));
|
||||
}
|
||||
|
||||
|
||||
getPreviousPeriod(currentDate: Date): Date {
|
||||
return new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1);
|
||||
const prevMonth = this.dateService.addMonths(currentDate, -1);
|
||||
const year = prevMonth.getFullYear();
|
||||
const month = prevMonth.getMonth();
|
||||
return this.dateService.startOfDay(new Date(year, month, 1));
|
||||
}
|
||||
|
||||
getPeriodLabel(date: Date): string {
|
||||
|
|
@ -140,15 +148,17 @@ export class MonthViewStrategy implements ViewStrategy {
|
|||
|
||||
getPeriodRange(baseDate: Date): { startDate: Date; endDate: Date } {
|
||||
// Month view shows events for the entire month grid (including partial weeks)
|
||||
const firstOfMonth = new Date(baseDate.getFullYear(), baseDate.getMonth(), 1);
|
||||
|
||||
const year = baseDate.getFullYear();
|
||||
const month = baseDate.getMonth();
|
||||
const firstOfMonth = this.dateService.startOfDay(new Date(year, month, 1));
|
||||
|
||||
// Get Monday of the week containing first day
|
||||
const weekBounds = this.dateService.getWeekBounds(firstOfMonth);
|
||||
const startDate = this.dateService.startOfDay(weekBounds.start);
|
||||
|
||||
|
||||
// End date is 41 days after start (42 total days)
|
||||
const endDate = this.dateService.addDays(startDate, 41);
|
||||
|
||||
|
||||
return {
|
||||
startDate,
|
||||
endDate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue