Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(mail-ingest): compare look-alike bookings at their wall time on any server zone

Mauriceeaa557343ec8
diff --git a/server/src/nest/mail-ingest/mail-ingest-process.service.ts b/server/src/nest/mail-ingest/mail-ingest-process.service.ts
index 92c032644..adfe5586e 100644
--- a/server/src/nest/mail-ingest/mail-ingest-process.service.ts
+++ b/server/src/nest/mail-ingest/mail-ingest-process.service.ts
@@ -260,7 +260,9 @@ export class MailIngestProcessService {
}
private async looksAlike(tripId: number, draft: MailDraft): Promise<boolean> {
- const start = Date.parse(bookingStart(draft.item) ?? '');
+ // A wall time without a zone, compared as text: shifted as UTC, it stays that wall time.
+ const wall = /^(\d{4}-\d{2}-\d{2})(?:T(\d{2}:\d{2}))?/.exec(bookingStart(draft.item) ?? '');
+ const start = wall ? Date.parse(`${wall[1]}T${wall[2] ?? '00:00'}:00Z`) : Number.NaN;
const window = (offset: number) =>
Number.isFinite(start) ? new Date(start + offset).toISOString().slice(0, 16) : null;
return this.candidates.tripHasSimilar(tripId, {
diff --git a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts
index 44ddd11fd..a5671cb26 100644
--- a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts
+++ b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts
@@ -557,6 +557,24 @@ describe('what a mail names', () => {
});
});
+ it('sees a booking at the same wall time as a look-alike whatever zone the server runs in', async () => {
+ const zone = process.env.TZ;
+ process.env.TZ = 'Asia/Tokyo';
+ try {
+ const user = await person();
+ await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' });
+ machine.mockResolvedValue([DINNER]);
+ await forward(user.id, eml('dinner', 'Fwd: Your table', BOTH));
+ machine.mockResolvedValue([{ ...DINNER, title: 'Sora dinner' }]);
+
+ const [again] = await entriesOf(await forward(user.id, eml('dinner-again', 'Fwd: Your table', BOTH)));
+ expect(again).toMatchObject({ resolution: 'pending', reason: 'possible_duplicate' });
+ } finally {
+ if (zone === undefined) delete process.env.TZ;
+ else process.env.TZ = zone;
+ }
+ });
+
});
describe('a mail that keeps failing', () => {