mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-20 13:51:45 +00:00
fix(transport): resolve Invalid Date on bookings in relative Day N trips
Transport bookings on trips without calendar dates (relative "Day N" mode)
stored a malformed "T10:00" string in reservation_time. Every display
surface used includes('T') + new Date() which yielded Invalid Date.
Add splitReservationDateTime() helper that classifies any reservation_time
shape (full datetime, date-only, bare HH:MM, or legacy "T10:00") into
{ date, time } parts. Fix TransportModal to store a clean bare HH:MM
instead of "T10:00" and update the read-back path. Route all display
surfaces (ReservationsPanel, DayDetailPanel, DayPlanSidebar,
PlaceInspector, SharedTripPage, TripPDF) through the helper, gating the
DATE column on a real calendar date and the TIME column on a time part.
Guard the ICS export to skip time-only reservation_time values instead of
emitting a malformed DTSTART. Backward-compatible: existing saved rows
with "T10:00" render correctly without a data migration.
This commit is contained in:
@@ -65,6 +65,18 @@ export function formatTime(timeStr: string | null | undefined, locale: string, t
|
||||
} catch { return timeStr }
|
||||
}
|
||||
|
||||
export function splitReservationDateTime(value?: string | null): { date: string | null; time: string | null } {
|
||||
if (!value) return { date: null, time: null }
|
||||
const isoDate = /^\d{4}-\d{2}-\d{2}$/
|
||||
if (value.includes('T')) {
|
||||
const [d, t] = value.split('T')
|
||||
return { date: isoDate.test(d) ? d : null, time: t ? t.slice(0, 5) : null }
|
||||
}
|
||||
if (isoDate.test(value)) return { date: value, time: null }
|
||||
if (/^\d{1,2}:\d{2}/.test(value)) return { date: null, time: value.slice(0, 5) }
|
||||
return { date: null, time: null }
|
||||
}
|
||||
|
||||
export function dayTotalCost(dayId: number, assignments: AssignmentsMap, currency: string): string | null {
|
||||
const da = assignments[String(dayId)] || []
|
||||
const total = da.reduce((s, a) => s + (parseFloat(a.place?.price || '') || 0), 0)
|
||||
|
||||
Reference in New Issue
Block a user