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:
Janus C. H. Knudsen 2025-10-03 20:59:52 +02:00
parent 6bbf2d8adb
commit a86a736340
6 changed files with 69 additions and 77 deletions

View file

@ -11,7 +11,7 @@ import { DragOffset, StackLinkData } from '../types/DragDropTypes';
import { ColumnBounds } from '../utils/ColumnDetectionUtils';
import { DragColumnChangeEventPayload, DragMoveEventPayload, DragStartEventPayload } from '../types/EventTypes';
import { DateService } from '../utils/DateService';
import { format, setHours, setMinutes, setSeconds, addDays } from 'date-fns';
import { format } from 'date-fns';
/**
* Interface for event rendering strategies
@ -164,40 +164,25 @@ export class DateEventRenderer implements EventRendererStrategy {
* Update data-start and data-end attributes with ISO timestamps
*/
private updateDateTimeAttributes(element: HTMLElement, columnDate: Date, startMinutes: number, endMinutes: number): void {
const startDate = this.createDateWithMinutes(columnDate, startMinutes);
let endDate = this.createDateWithMinutes(columnDate, endMinutes);
const startDate = this.dateService.createDateAtTime(columnDate, startMinutes);
let endDate = this.dateService.createDateAtTime(columnDate, endMinutes);
// Handle cross-midnight events
if (endMinutes >= 1440) {
const extraDays = Math.floor(endMinutes / 1440);
endDate = addDays(endDate, extraDays);
endDate = this.dateService.addDays(endDate, extraDays);
}
element.dataset.start = startDate.toISOString();
element.dataset.end = endDate.toISOString();
}
/**
* Create a date with specific minutes since midnight
*/
private createDateWithMinutes(baseDate: Date, totalMinutes: number): Date {
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
return setSeconds(setMinutes(setHours(baseDate, hours), minutes), 0);
}
/**
* Format minutes since midnight to time string
*/
private formatTimeFromMinutes(totalMinutes: number): string {
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
const date = new Date();
date.setHours(hours, minutes, 0, 0);
return format(date, 'HH:mm');
return this.dateService.minutesToTime(totalMinutes);
}
/**