#3980·moment

Incorrect month diff when time involved

Author: standyCreated May 26, 2017Updated Sep 2, 2026
LabelsBug

Adding some time to last day of month provides incorrect results on months diff

const a = moment([2017,1,28,1]); // 2017-02-28T01:00
const b = moment([2017,2,29,1]); // 2017-03-29T01:00
const c = moment([2017,2,31]);   // 2017-03-31T00:00
// a < b < c

console.log(b.diff(a, 'M')); // b - a === 1
console.log(c.diff(a, 'M')); // c - a === 0 
// cant be true, c almost 2 days later than b
// c - a = c - b + b - a = c - b + 1 >= 1

Tested with Crome 58 and Node 7.10.0

Fri May 26 2017 19:30:10 GMT+0300
26.05.2017, 19:30:10
-180
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36
2.18.1