title: Display time duration based on start and end date with interval using moment js
body: <p>I want to display array of durations given the startTime, endTime, and interval.</p>
  
  <pre><code>let value = {
    interval: '00:30:00',
    startTime: '03:00:00',
    endTime: '20:00:00'
  };
  </code></pre>
  
  <p>Sample output must be an array of durations with the given interval</p>
  
  <p>-startTime minus the interval, so the new <code>startTime = 02:30:00</code></p>
  
  <pre><code>[0] =&gt; '02:30 am - 03:00 am'
  [1] =&gt; '03:00 am - 03:30 am'
  [2] =&gt; '03:30 am - 04:00 am'
  [3] =&gt; '04:00 am - 04:30 am'
  ...... 
  [n] =&gt; '07:30 pm - 08:00 pm'
  </code></pre>
  
  <p>Here's my function</p>
  
  <pre><code>function showTimeIntervals(value) {
    let result = value.interval.split(","); 
    let start = "";
    let timeNotation = '';
    let time = '';
    for(let i in result) {
      let hr = moment(result[i], 'HH:mm').format('HH');
      let min = moment(result[i], 'HH:mm').format('mm');
      hr = (hr != 0) ? parseInt(hr, 10) : '';
      min = (min != 0) ? parseInt(min, 10) : '';
      if(hr != 0) {
        time = hr;
        timeNotation = 'hour';
        start = moment(value.startTime, 'hh:mm a').subtract(hr, 'hour');
      } else {
        time = min;
        timeNotation = 'minutes';
        start = moment(value.startTime, 'hh:mm a').subtract(min, 'minutes');
      }
    }
    var end = moment(value.endTime, 'hh:mm a');
    if(end &lt; start)
      end = end.add(1, 'd');
    var finalResult = [];
    var current = moment(start);
    while (current &lt;= end) {
      finalResult.push(current.format('hh:mm a'));
      current.add(time, timeNotation);
    }
    return finalResult;
  }
  </code></pre>
  
  <p>But it gives individual time not a duration</p>
  
  <pre><code> [0] =&gt; '02:30 am'
   [1] =&gt; '03:00 am'
   [2] =&gt; '03:30 am'
   [3] =&gt; '04:00 am'
   ......
   [n] =&gt; '08:00 pm'
  </code></pre>
  
  <p>Here's a fiddle -> <a href="https://jsfiddle.net/zm368de9/" rel="nofollow noreferrer">https://jsfiddle.net/zm368de9/</a></p>
  
  <p>Is there an easiest way a moment js can do that?</p>