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
allmoviestvshowslistsfilmography28 authored and zazzaz committed Aug 1, 2020
1 parent ec04ee3 commit 7afd8eb
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 7afd8eb

Please sign in to comment.