diff --git a/lib/cycle.js b/lib/cycle.js index 8fd7bd1..8de6723 100644 --- a/lib/cycle.js +++ b/lib/cycle.js @@ -40,7 +40,7 @@ export default function config(opts) { const lastMensesLocalDate = LocalDate.parse(lastMensesStart.date) const diffInDays = lastMensesLocalDate.until(targetDate, DAYS) // take maxCycleLength into account (we don't display cycle day numbers higher than 99 at the moment) - if (diffInDays >= 99) return null + if (diffInDays >= maxCycleLength) return null // cycle starts at day 1 return diffInDays + 1 } @@ -65,7 +65,6 @@ export default function config(opts) { } function getCycleForCycleStartDay(startDay) { - // TODO this needs to be made cycle length aware. all other places can go? const cycleStartIndex = cycleDaysSortedByDate.indexOf(startDay) const i = cycleStartsSortedByDate.indexOf(startDay) const nextMensesStart = cycleStartsSortedByDate[i - 1] diff --git a/test/cycle.spec.js b/test/cycle.spec.js index 232e2bc..8c746b0 100644 --- a/test/cycle.spec.js +++ b/test/cycle.spec.js @@ -71,6 +71,27 @@ describe('getCycleDayNumber', () => { const result = getCycleDayNumber(targetDate) expect(result).to.be.null() }) + + it('returns null if the cycle is longer than the max', function () { + const cycleStarts = [{ + date: '2018-05-09', + isCycleStart: true, + bleeding: { + value: 2 + } + }, { + date: '2018-05-03', + isCycleStart: true, + bleeding: { value: 2 } + }] + // we use the default 99 days max length + const getCycleDayNumber = cycleModule({ + cycleStartsSortedByDate: cycleStarts + }).getCycleDayNumber + const targetDate = '2018-08-16' + const result = getCycleDayNumber(targetDate) + expect(result).to.be.null() + }) }) describe('getPreviousCycle', () => {