#StackBounty: #javascript #reactjs #datetime #momentjs Difference between dates, rounded result to nearest minute

Bounty: 50

The difference between dates wants to round to the nearest minute.
Round date1,date2 down or up. The returned result is already rounded up to the full minute. I can modify date1,date2. Do not modify the result already returned

date2- date1

Code here: https://stackblitz.com/edit/react-azau4g

Example:

First step

this.state = {
  date1: "2019-06-29 21:25:38+00",
  date2: "2019-06-29T21:25:40.000+00:00"
}

round = (item) => {
  var m = moment(item);

  var roundUp = (m.second() || m.millisecond() ? m.add(1, 'minute').startOf('minute') : m.startOf('minute')).toISOString();
  return roundUp;
}

differentTime = {
    date1: this.state.date1.toISOString(),  
    date2: this.round(this.state.date2)   //return "2019-06-29T21:26:00.000+00:00"
}

Second step

Expected effect:

data2data1 = 1 min


Example 2

 this.state = {
      date1: "2019-06-29 21:25:01+00",
      date2: "2019-06-29T21:27:20.000+00:00"
    }



 differentTime2 = {
        date1: this.state.date1.toISOString(), 
        date2: this.round(this.state.date2)   //return "2019-06-29T21:28:00.000+00:00"
    }

Expecting effect:

date2date1 = 3 min


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.