mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
fix(trips): let a trip run past 365 days and refuse a longer range instead of clipping it
A trip longer than a year stopped at day 365: generateDays capped the day rows at MAX_TRIP_DAYS while the trip kept its full end date, so the last days had a date but no day to plan on, in the day list, the transport and booking dialogs and the phone's date pickers (#2403). The limit is MAX_TRIP_DAYS in @trek/shared now, 999 days, shared by the server, both trip forms and the MCP tools, and a range past it is refused rather than cut short: 400 on REST, an error result on MCP, bad params on the plugin RPC, and a message in the forms before anything is sent. The check runs before the trip row and the budget are touched, also catches a start date moved past the stored end on its own, and holds a day_count rebuild to the same bound. A trip that already carries a longer range can still be renamed. The MCP-only 90-day ceiling on create_trip goes with it; it clipped dated trips the same way. Closes #2403
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import {
|
||||
MAX_TRIP_DAYS,
|
||||
tripSpanDays,
|
||||
tripCreateRequestSchema,
|
||||
tripUpdateRequestSchema,
|
||||
tripAddMemberRequestSchema,
|
||||
@@ -21,6 +23,26 @@ describe('tripCreateRequestSchema', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('MAX_TRIP_DAYS', () => {
|
||||
it('lets a trip run past a year and keeps day numbers to three digits (#2403)', () => {
|
||||
expect(MAX_TRIP_DAYS).toBeGreaterThan(366);
|
||||
expect(MAX_TRIP_DAYS).toBeLessThan(1000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tripSpanDays', () => {
|
||||
it('counts both ends, across a leap day and a year boundary', () => {
|
||||
expect(tripSpanDays('2026-07-01', '2026-07-01')).toBe(1);
|
||||
expect(tripSpanDays('2026-07-01', '2026-07-07')).toBe(7);
|
||||
expect(tripSpanDays('2024-02-28', '2024-03-01')).toBe(3);
|
||||
expect(tripSpanDays('2025-01-26', '2026-01-28')).toBe(368);
|
||||
});
|
||||
|
||||
it('goes below one when the end precedes the start', () => {
|
||||
expect(tripSpanDays('2026-07-07', '2026-07-01')).toBe(-5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tripUpdateRequestSchema', () => {
|
||||
it('is fully partial and accepts is_archived + cover_image', () => {
|
||||
expect(tripUpdateRequestSchema.safeParse({}).success).toBe(true);
|
||||
|
||||
@@ -13,6 +13,25 @@ import { z } from 'zod';
|
||||
* permission checks + audit logging. Trip rows are wide, so responses stay open.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The most days a trip can have, whether from its date range or from the
|
||||
* `day_count` of a dateless trip. A range longer than this is refused rather
|
||||
* than cut short: a trip whose end date lies past its last day is exactly the
|
||||
* kind of half-state #2403 reported, and a mistyped year is easier to spot as
|
||||
* an error than as a few hundred empty days. Three digits keep every day badge
|
||||
* in the planner intact.
|
||||
*/
|
||||
export const MAX_TRIP_DAYS = 999;
|
||||
|
||||
/** Calendar days in an inclusive YYYY-MM-DD range, counted the same way on both sides of the wire. */
|
||||
export function tripSpanDays(startDate: string, endDate: string): number {
|
||||
const utcDay = (date: string) => {
|
||||
const [y = NaN, m = NaN, d = NaN] = date.split('-').map(Number);
|
||||
return Date.UTC(y, m - 1, d);
|
||||
};
|
||||
return Math.floor((utcDay(endDate) - utcDay(startDate)) / 86400000) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trip entity as returned by the trip list / get / create / update endpoints
|
||||
* (server/src/services/tripService.ts -> TRIP_SELECT). Columns of the `trips`
|
||||
|
||||
Reference in New Issue
Block a user