Skip to content

Commit

Permalink
Fix: update calculateTotalPrice to loop until the last day is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Feb 10, 2025
1 parent b042b63 commit 4366649
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/bookcars-helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ export const calculateTotalPrice = (car: bookcarsTypes.Car, from: Date, to: Date

// Reset time to 00:00:00 before loop
currentDate.setHours(0, 0, 0, 0)
to.setHours(0, 0, 0, 0) // Ensure endDate is also normalized

// Loop until the day before endDate
while (currentDate.getTime() < to.getTime()) {
// Loop until the last day is reached
let currentDay = 1
while (currentDay <= totalDays) {
let applicableRate = (car.discountedDailyPrice || car.dailyPrice)

// Check if a custom rate applies
Expand All @@ -283,6 +283,7 @@ export const calculateTotalPrice = (car: bookcarsTypes.Car, from: Date, to: Date
totalPrice += applicableRate
currentDate.setDate(currentDate.getDate() + 1)
currentDate.setHours(0, 0, 0, 0); // Ensure time is reset
currentDay += 1
}
} else {
let remainingDays = totalDays
Expand Down

0 comments on commit 4366649

Please sign in to comment.