From 5d860bde83f250c0f79d701a272fc89bd9fd1d91 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Tue, 28 Jul 2026 17:22:42 -0400 Subject: [PATCH] Enhance date handling in location and transportation components by introducing utility functions for managing all-day events. Updated all-day toggle logic to utilize new functions for converting local dates to date-only format and setting default times for timed inputs. --- .../locations/LocationVisits.svelte | 47 ++++++++++++------- .../components/lodging/LodgingDetails.svelte | 27 +++++++---- .../TransportationDetails.svelte | 27 +++++++---- frontend/src/lib/dateUtils.ts | 13 +++++ 4 files changed, 77 insertions(+), 37 deletions(-) diff --git a/frontend/src/lib/components/locations/LocationVisits.svelte b/frontend/src/lib/components/locations/LocationVisits.svelte index 88f28057..160431f8 100644 --- a/frontend/src/lib/components/locations/LocationVisits.svelte +++ b/frontend/src/lib/components/locations/LocationVisits.svelte @@ -9,7 +9,14 @@ } from '$lib/types'; import TimezoneSelector from '../TimezoneSelector.svelte'; import { t } from 'svelte-i18n'; - import { updateLocalDate, updateUTCDate, validateDateRange, formatUTCDate } from '$lib/dateUtils'; + import { + updateLocalDate, + updateUTCDate, + validateDateRange, + formatUTCDate, + toDateOnlyLocal, + toTimedLocalDefault + } from '$lib/dateUtils'; import { onMount } from 'svelte'; import { isAllDay, isVisitAllDay, allDayDatePart, SPORT_TYPE_CHOICES } from '$lib'; import { createEventDispatcher } from 'svelte'; @@ -52,7 +59,7 @@ // Types // Component state - let allDay: boolean = false; + let allDay: boolean = true; let localStartDate: string = ''; let localEndDate: string = ''; let fullStartDate: string = ''; @@ -205,15 +212,19 @@ }).utcDate; } - function handleAllDayToggle() { - if (allDay) { - localStartDate = localStartDate ? localStartDate.split('T')[0] : ''; - localEndDate = localEndDate ? localEndDate.split('T')[0] : ''; + function handleAllDayToggle(event: Event) { + const nextAllDay = (event.currentTarget as HTMLInputElement).checked; + + if (nextAllDay) { + localStartDate = toDateOnlyLocal(localStartDate); + localEndDate = toDateOnlyLocal(localEndDate); } else { - localStartDate = localStartDate + 'T00:00'; - localEndDate = localEndDate + 'T23:59'; + localStartDate = toTimedLocalDefault(localStartDate); + localEndDate = toTimedLocalDefault(localEndDate, true); } + allDay = nextAllDay; + utcStartDate = updateUTCDate({ localDate: localStartDate, timezone: selectedStartTimezone, @@ -226,15 +237,17 @@ allDay }).utcDate; - localStartDate = updateLocalDate({ - utcDate: utcStartDate, - timezone: selectedStartTimezone - }).localDate; + if (!allDay) { + localStartDate = updateLocalDate({ + utcDate: utcStartDate, + timezone: selectedStartTimezone + }).localDate; - localEndDate = updateLocalDate({ - utcDate: utcEndDate, - timezone: selectedStartTimezone - }).localDate; + localEndDate = updateLocalDate({ + utcDate: utcEndDate, + timezone: selectedStartTimezone + }).localDate; + } } async function addVisit(isAuto: boolean = false) { @@ -917,7 +930,7 @@ id="all-day-toggle" type="checkbox" class="toggle toggle-{typeConfig.color} toggle-sm" - bind:checked={allDay} + checked={allDay} on:change={handleAllDayToggle} /> diff --git a/frontend/src/lib/components/lodging/LodgingDetails.svelte b/frontend/src/lib/components/lodging/LodgingDetails.svelte index a30161ae..b3b8cb60 100644 --- a/frontend/src/lib/components/lodging/LodgingDetails.svelte +++ b/frontend/src/lib/components/lodging/LodgingDetails.svelte @@ -1,7 +1,13 @@