Refactor date handling components: Replace DateRangeDropdown with DateRangeCollapse

- Introduced DateRangeCollapse.svelte to manage date range selection with timezone support.
- Removed DateRangeDropdown.svelte as it was redundant.
- Updated LodgingModal and TransportationModal to utilize DateRangeCollapse for date selection.
- Enhanced date conversion utilities to handle all-day events correctly.
- Adjusted TimezoneSelector for improved accessibility and focus management.
- Updated date handling logic in dateUtils.ts to support all-day events.
- Modified test page to reflect changes in date range component usage.
This commit is contained in:
Sean Morley
2025-05-09 10:24:29 -04:00
parent 827b150965
commit 2c50ca0b1a
8 changed files with 484 additions and 758 deletions

View File

@@ -26,10 +26,22 @@ export function toLocalDatetime(
*/
export function toUTCDatetime(
localDate: string,
timezone: string = Intl.DateTimeFormat().resolvedOptions().timeZone
timezone: string = Intl.DateTimeFormat().resolvedOptions().timeZone,
allDay: boolean = false
): string | null {
if (!localDate) return null;
return DateTime.fromISO(localDate, { zone: timezone }).toUTC().toISO();
if (allDay) {
// Treat input as date-only, set UTC midnight manually
return DateTime.fromISO(localDate, { zone: 'UTC' })
.startOf('day')
.toISO({ suppressMilliseconds: true });
}
// Normal timezone conversion for datetime-local input
return DateTime.fromISO(localDate, { zone: timezone })
.toUTC()
.toISO({ suppressMilliseconds: true });
}
/**
@@ -54,9 +66,17 @@ export function updateLocalDate({
* @param params Object containing local date and timezone
* @returns Object with updated UTC datetime string
*/
export function updateUTCDate({ localDate, timezone }: { localDate: string; timezone: string }) {
export function updateUTCDate({
localDate,
timezone,
allDay = false
}: {
localDate: string;
timezone: string;
allDay?: boolean;
}) {
return {
utcDate: toUTCDatetime(localDate, timezone)
utcDate: toUTCDatetime(localDate, timezone, allDay)
};
}