Skip to content

Commit

Permalink
fix: update monthDiff function to get more accurate results
Browse files Browse the repository at this point in the history
  • Loading branch information
zazzaz committed Aug 1, 2020
1 parent f7c71fc commit 19e8a7f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ const padZoneStr = (instance) => {

const monthDiff = (a, b) => {
// function from moment.js in order to keep the same result
if (a.date() < b.date()) return -monthDiff(b, a)
const wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month())
const anchor = a.clone().add(wholeMonthDiff, C.M)
const anchor = a.add(wholeMonthDiff, C.M)
const c = b - anchor < 0
const anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), C.M)
return Number(-(wholeMonthDiff + ((b - anchor) / (c ? (anchor - anchor2) :
const anchor2 = a.add(wholeMonthDiff + (c ? -1 : 1), C.M)
return +(-(wholeMonthDiff + ((b - anchor) / (c ? (anchor - anchor2) :
(anchor2 - anchor)))) || 0)
}

Expand Down

0 comments on commit 19e8a7f

Please sign in to comment.