Files
calchat/packages/shared/src/utils/dateHelpers.ts
Linus Waldowsky 6f0d172bf2 feat: add EditEventScreen with calendar and chat mode support
Add a unified event editor that works in two modes:
- Calendar mode: Create/edit events directly via EventService API
- Chat mode: Edit AI-proposed events before confirming them

The chat mode allows users to modify proposed events (title, time,
recurrence) and persists changes both locally and to the server.

New components: DateTimePicker, ScrollableDropdown, useDropdownPosition
New API: PUT /api/chat/messages/:messageId/proposal
2026-01-31 18:46:31 +01:00

49 lines
1.4 KiB
TypeScript

import { Day, DAY_INDEX } from "../models/Constants";
/**
* Get a date for a specific weekday relative to today.
* @param day - The target day (e.g., "Friday")
* @param offset - 1 = next occurrence, 2 = the one after, -1 = last occurrence, etc.
* @param hour - Hour of day (0-23)
* @param minute - Minute (0-59)
*/
export function getDay(
day: Day,
offset: number,
hour: number,
minute: number,
): Date {
const today = new Date();
const currentDay = today.getDay();
const targetDay = DAY_INDEX[day];
let daysUntil = targetDay - currentDay;
if (offset > 0) {
// Future: if target is today or past, move to next week
if (daysUntil <= 0) daysUntil += 7;
daysUntil += (offset - 1) * 7;
} else if (offset < 0) {
// Past: if target is today or future, move to last week
if (daysUntil >= 0) daysUntil -= 7;
daysUntil += (offset + 1) * 7;
}
const result = new Date(today);
result.setDate(today.getDate() + daysUntil);
result.setHours(hour, minute, 0, 0);
return result;
}
/**
* Check if an event spans multiple days.
* Compares dates at midnight to determine if start and end are on different calendar days.
*/
export function isMultiDayEvent(start: Date, end: Date): boolean {
const startDate = new Date(start);
const endDate = new Date(end);
startDate.setHours(0, 0, 0, 0);
endDate.setHours(0, 0, 0, 0);
return startDate.getTime() !== endDate.getTime();
}