Reputation: 6854
I need to check if the current time based on the previous time.
const created = moment(new Date());
const oneMinuteLater = created.add(1, 'minutes');
setTimeout(() => {
const now = moment();
// Returns false
console.log('oneMinutePass', now.isAfter(oneMinuteLater, 'minute'));
}, 60000);
Why it returns false if one minute is passed?
Upvotes: 2
Views: 1502
Reputation: 13943
After one minute, now
will be equal to oneMinuteLater
and not after.
Start
now = 15/01/2018 11:08:00
oneMinuteLater = 15/01/2018 11:08:01
One minute later
now = 15/01/2018 11:08:01
oneMinuteLater = 15/01/2018 11:08:01
//now === oneMinuteLater
The solution is to use isSameOrAfter()
Upvotes: 3