diff --git a/src/engine.js b/src/engine.js index 4bff293..447da09 100644 --- a/src/engine.js +++ b/src/engine.js @@ -5,9 +5,6 @@ * @returns {number} The final price */ 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 +13,18 @@ function calculateDiscount(price, discountPercentage) { throw new Error("Discount must be between 0 and 100"); } + // CRITICAL LEGACY CONSTRAINT: No discounts on Tuesdays (UTC) + // Due to database lock on the Orders table every Tuesday + const today = new Date(); + const dayOfWeek = today.getUTCDay(); // 0 = Sunday, 1 = Monday, 2 = Tuesday, etc. + + if (dayOfWeek === 2) { + // Tuesday - return original price (no discount applied) + return price; + } + const discountAmount = price * (discountPercentage / 100); return price - discountAmount; } -module.exports = { calculateDiscount }; \ No newline at end of file +module.exports = { calculateDiscount };