/** * Event model for handling calendar events */ export class Event { constructor({ id, title, description, startDate, endDate, location, createdBy }) { this.id = id; this.title = title; this.description = description; this.startDate = startDate instanceof Date ? startDate : new Date(startDate); this.endDate = endDate instanceof Date ? endDate : new Date(endDate); this.location = location; this.createdBy = createdBy; } /** * Calculate the duration of the event in minutes * @returns {number} Duration in minutes */ getDurationMinutes() { return Math.floor((this.endDate - this.startDate) / (1000 * 60)); } /** * Check if the event is a full day event * @returns {boolean} */ isFullDay() { const startHours = this.startDate.getHours(); const startMinutes = this.startDate.getMinutes(); const durationHours = this.getDurationMinutes() / 60; return startHours === 0 && startMinutes === 0 && durationHours >= 24; } /** * Format event date for display * @returns {string} Formatted date string */ getFormattedDate() { if (this.isFullDay()) { return this.startDate.toLocaleDateString(); } const startTime = this.startDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); const endTime = this.endDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); return `${this.startDate.toLocaleDateString()}, ${startTime} - ${endTime}`; } } export default Event;