From c6a75a838ba237d0a9a3f17d63c8b60ebed41050 Mon Sep 17 00:00:00 2001 From: JhiNResH Date: Fri, 24 Jul 2026 11:29:10 -0700 Subject: [PATCH] fix: align queue ETA with capacity window --- src/core/orders.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/orders.ts b/src/core/orders.ts index eb88329..0f75396 100644 --- a/src/core/orders.ts +++ b/src/core/orders.ts @@ -130,13 +130,16 @@ export async function estimatedPickupWaitMinutes( const capacity = CAPACITY_BY_PRODUCTION_CLASS[productionClass]; const prepMinutes = Math.max(item.prepMinutes || 5, 1); const queueWait = prepMinutes + Math.floor(activeAhead / capacity) * CAPACITY_WINDOW_MINUTES; - const desiredReadyAt = addMinutes(now, prepMinutes); + const desiredReadyAt = addMinutes(now, queueWait); for (let offset = 0; offset < 32; offset += 1) { const probeAt = addMinutes(desiredReadyAt, offset * CAPACITY_WINDOW_MINUTES); const window = await capacityWindowAt(merchantId, productionClass, probeAt); if (window.available >= quantity) { - const capacityWait = prepMinutes + offset * CAPACITY_WINDOW_MINUTES; - return Math.max(queueWait, capacityWait); + const windowWait = Math.max( + 0, + Math.ceil((new Date(window.startsAt).getTime() - now.getTime()) / 60_000), + ); + return Math.max(queueWait, windowWait); } } return Math.max(queueWait, prepMinutes + 32 * CAPACITY_WINDOW_MINUTES);