Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. const searchOverlappingDatesInMatrix = ({ startDates, leaseTermFromMatrix, startDate, endDate, timezone }) => {
  2. let matchingStartDateIndex = startDates.findIndex(index => dateInBetween(index, leaseTermFromMatrix[index].endDate, startDate));
  3. const overlappingMatrixPrices = [];
  4.  
  5. // If we did not find it, that could mean the startDate is before the priceMatrix start date
  6. if (matchingStartDateIndex <= 0) {
  7. // 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
  8. if (startDate <= startDates[0]) {
  9. matchingStartDateIndex = 0;
  10. } else {
  11. return overlappingMatrixPrices;
  12. }
  13. }
  14.  
  15. // We get all the prices between the matchingStartDateIndex and the provided end date
  16. const lastIndex = startDates.length - 1;
  17. for (let i = matchingStartDateIndex; i <= lastIndex; i++) {
  18. const currentStartDate = startDates[i];
  19. // If the current start date is after the end date, that means we should not continue
  20. if (currentStartDate > endDate) {
  21. break;
  22. }
  23.  
  24. overlappingMatrixPrices.push({ startDate: parseAsInTimezone(currentStartDate, { timezone }), ...leaseTermFromMatrix[currentStartDate] });
  25. }
  26.  
  27. return overlappingMatrixPrices;
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement