mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 14:36:31 +00:00
3b933470d3
A booking linked to a stop has two days to go by, its own date and the stop's. They part when the stop is moved to another day or the trip is shifted with "keep bookings on their dates", and the plan then listed the booking at the stop and again in the timeline of its own day. The stop now wins wherever both are drawn: the desktop day plan and day detail, the phone's plan tab and day sheet, and the road trip rail on both. The booking's date is left as it is; a stop on one of the booking's own days changes nothing, so a rental picked up at a stop still runs across its other days. Refs #2604
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import type { Accommodation, Reservation } from '../../types';
|
|
|
|
type Translate = (key: string, params?: Record<string, string | number>) => string;
|
|
|
|
/**
|
|
* The bookings of a day, hotels aside (they have their own block): the ones hanging
|
|
* on one of the day's stops and the ones booked on the day itself. `pinnedAway` leaves
|
|
* a booking whose stop sits on another day to that stop (#2604).
|
|
*/
|
|
export function dayBookings<R extends Pick<Reservation, 'type' | 'assignment_id' | 'day_id'>>(
|
|
dayId: number,
|
|
dayAssignments: { id: number }[],
|
|
reservations: R[],
|
|
pinnedAway?: (r: Pick<Reservation, 'assignment_id' | 'day_id' | 'end_day_id'>) => boolean
|
|
): R[] {
|
|
return reservations.filter((r) => {
|
|
if (r.type === 'hotel') return false;
|
|
if (r.assignment_id && dayAssignments.some((a) => a.id === r.assignment_id)) return true;
|
|
return r.day_id === dayId && !pinnedAway?.(r);
|
|
});
|
|
}
|
|
|
|
/** A forecast temperature (always in °C from the API) rounded in the user's unit. */
|
|
export function toDisplayTemp(celsius: number | undefined, fahrenheit: boolean): number {
|
|
return Math.round(fahrenheit ? ((celsius ?? Number.NaN) * 9) / 5 + 32 : (celsius ?? Number.NaN));
|
|
}
|
|
|
|
/** What a stay means for the day: check-in, check-out, both, or nothing (a night in between). */
|
|
export function stayDayLabel(
|
|
acc: Pick<Accommodation, 'start_day_id' | 'end_day_id'>,
|
|
dayId: number | undefined,
|
|
t: Translate
|
|
): string | null {
|
|
const checksIn = acc.start_day_id === dayId;
|
|
const checksOut = acc.end_day_id === dayId;
|
|
if (checksIn && checksOut) return `${t('day.checkIn')} & ${t('day.checkOut')}`;
|
|
if (checksIn) return t('day.checkIn');
|
|
if (checksOut) return t('day.checkOut');
|
|
return null;
|
|
}
|