Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const searchOverlappingDatesInMatrix = ({ startDates, leaseTermFromMatrix, startDate, endDate, timezone }) => {
- let matchingStartDateIndex = startDates.findIndex(index => dateInBetween(index, leaseTermFromMatrix[index].endDate, startDate));
- const overlappingMatrixPrices = [];
- // If we did not find it, that could mean the startDate is before the priceMatrix start date
- if (matchingStartDateIndex <= 0) {
- // We check if the start date is before, if not that means the start date is after the price matrix end date, so we return
- if (startDate <= startDates[0]) {
- matchingStartDateIndex = 0;
- } else {
- return overlappingMatrixPrices;
- }
- }
- // We get all the prices between the matchingStartDateIndex and the provided end date
- const lastIndex = startDates.length - 1;
- for (let i = matchingStartDateIndex; i <= lastIndex; i++) {
- const currentStartDate = startDates[i];
- // If the current start date is after the end date, that means we should not continue
- if (currentStartDate > endDate) {
- break;
- }
- overlappingMatrixPrices.push({ startDate: parseAsInTimezone(currentStartDate, { timezone }), ...leaseTermFromMatrix[currentStartDate] });
- }
- return overlappingMatrixPrices;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement