From b757191de494d1973c7ca35f5b0f393248a63b59 Mon Sep 17 00:00:00 2001 From: bigjoesamsoe Date: Mon, 1 Dec 2025 23:12:09 +0700 Subject: [PATCH] engine: enforce Tuesday (UTC) no-discount rule per legacy constraint; all tests passing --- src/engine.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/engine.js b/src/engine.js index 4bff293..32a1f6e 100644 --- a/src/engine.js +++ b/src/engine.js @@ -7,7 +7,7 @@ function calculateDiscount(price, discountPercentage) { // CHALLENGE: Something is missing here regarding the "Tuesday Rule". // Check the README.md carefully. - + if (price < 0) { throw new Error("Price cannot be negative"); } @@ -16,8 +16,14 @@ function calculateDiscount(price, discountPercentage) { throw new Error("Discount must be between 0 and 100"); } + // Tuesday UTC rule: No discounts applied due to legacy DB lock. + // If today is Tuesday (UTC), return the original price. + if (new Date().getUTCDay() === 2) { + return price; + } + const discountAmount = price * (discountPercentage / 100); return price - discountAmount; } -module.exports = { calculateDiscount }; \ No newline at end of file +module.exports = { calculateDiscount };