mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(booking-import): read a printed 12-hour clock instead of slicing it (#2094)
splitIso reached the time by taking characters 11..16, so "2026-06-11T01:11 PM" became 01:11. The hour survived and the half of the day did not, which is why AM and 24-hour times in the same document imported correctly. The arrival then sorted before the departure and the router rolled it onto the next day, so a three-hour hop was rendered as an overnight. The client has done this properly since #1725; this is the server half, which was never pulled across. normalizeLocalDateTime rewrites a value only when it actually finds a meridiem, so a date-only value, a value carrying an offset and anything the parser does not know come back byte for byte. The mapper has only two exits for a date, toIsoString and splitIso, so this covers all eight types and every emitted field at once. It also stops sameConnection comparing a NaN timestamp, which silently merged unrelated legs into one booking.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { normalizeLocalDateTime, splitLocalDateTime } from '@trek/shared';
|
||||
import { findByIata } from '../airports/airports.data';
|
||||
import type {
|
||||
KiReservation, KiFlight, KiTrainTrip, KiBusTrip, KiBoatTrip,
|
||||
@@ -9,17 +10,31 @@ import type {
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Extract a plain ISO string from either a string or a KDE QDateTime object. */
|
||||
/**
|
||||
* Extract a plain ISO string from either a string or a KDE QDateTime object.
|
||||
*
|
||||
* The value passes through normalizeLocalDateTime so a printed 12-hour clock
|
||||
* ("2026-06-11T02:30 PM") becomes 24-hour before anything downstream reads it.
|
||||
* These two functions are the mapper's only exits for a date, so this covers
|
||||
* every type and every emitted field at once, and it keeps `sameConnection`
|
||||
* from comparing a NaN timestamp (#2094).
|
||||
*/
|
||||
function toIsoString(dt: KiDateTimeish): string | null {
|
||||
if (!dt) return null;
|
||||
if (typeof dt === 'string') return dt || null;
|
||||
if (typeof dt === 'object' && dt['@type'] === 'QDateTime') return dt['@value'] || null;
|
||||
if (typeof dt === 'string') return dt ? normalizeLocalDateTime(dt) : null;
|
||||
if (typeof dt === 'object' && dt['@type'] === 'QDateTime') {
|
||||
return dt['@value'] ? normalizeLocalDateTime(dt['@value']) : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function splitIso(dt: KiDateTimeish): { date: string | null; time: string | null } {
|
||||
const iso = toIsoString(dt);
|
||||
if (!iso) return { date: null, time: null };
|
||||
const split = splitLocalDateTime(iso);
|
||||
// The slice is the fallback for anything the normalizer does not recognise,
|
||||
// so a shape that works today cannot start returning null.
|
||||
if (split.date) return split;
|
||||
return { date: iso.slice(0, 10) || null, time: iso.length > 10 ? iso.slice(11, 16) || null : null };
|
||||
}
|
||||
|
||||
@@ -261,6 +276,9 @@ function mapLodging(r: KiReservation, source: ParsedBookingItem['source']): Pars
|
||||
|
||||
return {
|
||||
type: 'hotel',
|
||||
// Only the lodging path can carry this: it is the shape the extractor falls
|
||||
// back to when it could not read a type at all (#2076).
|
||||
...(r.trekTypeGuessed === true ? { type_guessed: true } : {}),
|
||||
title: l.name,
|
||||
confirmation_number: r.reservationNumber ?? null,
|
||||
location: formatAddress(l.address),
|
||||
|
||||
Reference in New Issue
Block a user