bugproof-demo-shoplite · case_20260926_2c6c
Delivery date shows one day early for orders after 8 PM IST
The delivery estimate feature calculated the wrong delivery date for orders placed late in the evening Indian Standard Time (IST). The code incorrectly used the order's UTC timestamp instead of the IST hour to determine whether to add a day to the estimate. The line of code was corrected to use the order's IST hour when checking the dispatch cutoff, fixing the incorrect delivery date calculation.
Written by IBM watsonx.ai ibm/granite-4-h-small from the case evidence.
Reproduced — a new test failed before the fix
1 of 1 repro test failed on the unfixed code
AssertionError: expected '2026-03-13' to be '2026-03-14' // Object.is equality
Culprit commit identified
Pinned by git bisect in 5 steps · matches the seeded answer key · found by a follow-up bisect after publishing
b4369d9 perf(delivery): compute IST date without Intl.DateTimeFormat
Fixed — the repro test and the full suite pass
113 of 113 tests pass after the fix
Reviewed — the Critic approved
Fix is correct: changes orderedAt.getUTCHours() to ist.getUTCHours() — directly addresses root cause
APPROVED
Tests untouched — the fix changed no existing test
The fix commit only adds the repro test; no existing test was modified or deleted (git diff of the fix commit)
+ tests/bugproof/bug-03-delivery-estimate.test.ts
Written by the Fixer, whose edit permission covers src/ only; the check above confirms no existing test changed.
--- a/src/delivery/estimate.ts +++ b/src/delivery/estimate.ts @@ -34 +34 @@ - if (orderedAt.getUTCHours() >= DISPATCH_CUTOFF_HOUR) dispatch += DAY_MS; + if (ist.getUTCHours() >= DISPATCH_CUTOFF_HOUR) dispatch += DAY_MS;
The repro test fails on the code before the fix and passes on the fix.
git clone https://github.com/GegarinSagolsem/bugproof-demo-shoplite && cd bugproof-demo-shoplite && npm ci git checkout 31835d5~1 # the code before the fix git checkout 31835d5 -- tests/bugproof/bug-03-delivery-estimate.test.ts # add the repro test npx vitest run tests/bugproof/bug-03-delivery-estimate.test.ts # fails: the bug is reproduced git checkout 31835d5 # the fix npx vitest run tests/bugproof/bug-03-delivery-estimate.test.ts # passes
commit b4369d97a0663fe9843099d55b2dd5d95a2728fe
Author: GegarinSagolsem <176033453+GegarinSagolsem@users.noreply.github.com>
Date: Fri Sep 25 18:55:53 2026 +0000
perf(delivery): compute IST date without Intl.DateTimeFormat
---
src/delivery/estimate.ts | 29 ++++++-----------------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/src/delivery/estimate.ts b/src/delivery/estimate.ts
index ff67f73..4a28bc9 100644
--- a/src/delivery/estimate.ts
+++ b/src/delivery/estimate.ts
@@ -6,26 +6,9 @@ export const DEFAULT_TRANSIT_DAYS = 3;
const DAY_MS = 24 * 60 * 60 * 1000;
const SUNDAY = 0;
-interface CalendarTime {
- year: number;
- month: number;
- day: number;
- hour: number;
-}
-
-/** Wall-clock date and hour of an instant in India Standard Time. */
-function istCalendar(instant: Date): CalendarTime {
- const parts = new Intl.DateTimeFormat("en-GB", {
- timeZone: DELIVERY_TIME_ZONE,
- year: "numeric",
- month: "2-digit",
- day: "2-digit",
- hour: "2-digit",
- hourCycle: "h23",
- }).formatToParts(instant);
- const get = (type: Intl.DateTimeFormatPartTypes) => Number(parts.find((part) => part.type === type)?.value);
- return { year: get("year"), month: get("month"), day: get("day"), hour: get("hour") };
-}
+// India has no daylight saving, so IST is always UTC+05:30. Shifting the timestamp is much
+// cheaper than building an Intl.DateTimeFormat on every cart render.
+const IST_OFFSET_MS = (5 * 60 + 30) * 60 * 1000;
/** Couriers do not deliver on Sundays, so Sundays are not counted as transit days. */
function addDeliveryDays(start: number, days: number): number {
@@ -46,9 +29,9 @@ function toIsoDate(epochMs: number): string {
* Dispatch happens on the IST order date, or the next day after the 8 PM cutoff.
*/
export function estimateDelivery(orderedAt: Date, transitDays: number = DEFAULT_TRANSIT_DAYS): string {
- const { year, month, day, hour } = istCalendar(orderedAt);
- let dispatch = Date.UTC(year, month - 1, day);
- if (hour >= DISPATCH_CUTOFF_HOUR) dispatch += DAY_MS;
+ const ist = new Date(orderedAt.getTime() + IST_OFFSET_MS);
+ let dispatch = Date.UTC(ist.getUTCFullYear(), ist.getUTCMonth(), ist.getUTCDate());
+ if (orderedAt.getUTCHours() >= DISPATCH_CUTOFF_HOUR) dispatch += DAY_MS;
return toIsoDate(addDeliveryDays(dispatch, transitDays));
}
Updated after publishing: a follow-up bisect on 2026-09-26 04:42 UTC identified the culprit b4369d9. The Lead wrote the summary below before that.
Bug in src/delivery/estimate.ts line 34: dispatch cutoff compared orderedAt.getUTCHours() (UTC) instead of ist.getUTCHours() (IST), causing orders placed after 20:00 IST but before midnight UTC to miss the cutoff and deliver one day early. Fix: change orderedAt to ist on that single line. Repro test (tests/bugproof/bug-03-delivery-estimate.test.ts) confirmed RED before fix and GREEN after. Full suite: 113/113 passed. Critic approved.