Quantcast
Viewing all articles
Browse latest Browse all 6404

how to set remaining values to last slots

Divide all the total seating capacities during the selected start and end time equally among the slots created. But, if some capacitiesare exceeding the rounding values then distribute/divide the slot seating capacities to the last slots.Example: User has selected the start time as tomorrow at start time 11:00 and end time as 11:45. And the total seating capacity as 6.So, the 15 mins slots will be created as:

TimingSeating Capacity
11:00 - 11:151
11:15 - 11:301
11:30- 11:452
11:45 - 12:002

I need the above result. I have done it using the below code, but no success.

    const timePair = timePairs(      calculate('11:00','12:00'      )    );    console.log(timePair);    if (timePair.length === values.capacity) {      console.log(        map(timePair, (element) => extend({}, element, { capacity: 1 }))      );    } else if (values.capacity < timePair.length) {      console.log(        map(timePair, (element) =>          extend({}, element, { capacity: 1 })        ).slice(0, values.capacity)      );    } else {      if (timePair.length === 1) {        console.log(          map(timePair, (element) =>            extend({}, element, { capacity: values.capacity })          )        );      } else if (timePair.length < values.capacity) {        console.log(          map(timePair, (element) =>            extend({}, element, {              capacity: Math.round(values.capacity / timePair.length),            })          )        );      } else {        const balance = Math.round(values.capacity / timePair.length);        console.log(balance);      }    }const calculate = (openTime: any, closeTime: any) => {    const x = {      slotInterval: 15,      openTime: openTime,      closeTime: closeTime,    };    const startTime = moment(x.openTime, "HH:mm");    const endTime = moment(x.closeTime, "HH:mm");    const allTimes = [];    while (startTime <= endTime) {      allTimes.push(startTime.format("HH:mm"));      startTime.add(x.slotInterval, "minutes");    }    return allTimes;};const timePairs = (times: any) => {    const result = [];    for (let i = 0, n = times.length; i + 1 < n; i += 1) {      result.push({ start: times[i], end: times[i + 1] });    }    return result;};

The output for the above code is,

[{"start": "11:00", "end": "11:15", "capacity": 2}, {"start": "11:15", "end": "11:30", "capacity": 2}, {"start": "11:30", "end": "11:45", "capacity": 2}, {"start": "11:45", "end": "12:00", "capacity": 2}]

I want the output as (if capacity is 6),

[{"start": "11:00", "end": "11:15", "capacity": 1}, {"start": "11:15", "end": "11:30", "capacity": 1}, {"start": "11:30", "end": "11:45", "capacity": 2}, {"start": "11:45", "end": "12:00", "capacity": 2}]

I want the output as (if capacity is 7),

[{"start": "11:00", "end": "11:15", "capacity": 1}, {"start": "11:15", "end": "11:30", "capacity": 1}, {"start": "11:30", "end": "11:45", "capacity": 2}, {"start": "11:45", "end": "12:00", "capacity": 3}]


Viewing all articles
Browse latest Browse all 6404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>