Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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 };
module.exports = { calculateDiscount };