Fix cycle length in getCycle
This commit is contained in:
+13
-6
@@ -61,32 +61,39 @@ export default function config(opts) {
|
||||
if (startFromHere < 0) return null
|
||||
return cycleStartsSortedByDate
|
||||
.slice(startFromHere)
|
||||
.map(getCycleForCycleStartDay)
|
||||
// filter the ones exceeding macCycleLength
|
||||
.map(start => getCycleForCycleStartDay(start))
|
||||
// filter the ones exceeding maxCycleLength, those are null
|
||||
.filter(cycle => cycle)
|
||||
}
|
||||
|
||||
function getCycleForCycleStartDay(startDay) {
|
||||
function getCycleForCycleStartDay(startDay, todayDate) {
|
||||
const todayAsLocalDate = todayDate ? LocalDate.parse(todayDate) : LocalDate.now()
|
||||
const cycleStartIndex = cycleDaysSortedByDate.indexOf(startDay)
|
||||
const i = cycleStartsSortedByDate.indexOf(startDay)
|
||||
const startLocalDate = LocalDate.parse(startDay.date)
|
||||
const nextMensesStart = cycleStartsSortedByDate[i - 1]
|
||||
let cycle
|
||||
let cycleLength
|
||||
if (nextMensesStart) {
|
||||
cycle = cycleDaysSortedByDate.slice(
|
||||
cycleDaysSortedByDate.indexOf(nextMensesStart) + 1,
|
||||
cycleStartIndex + 1,
|
||||
)
|
||||
const nextLocalDate = LocalDate.parse(nextMensesStart.date)
|
||||
cycleLength = startLocalDate.until(nextLocalDate, DAYS)
|
||||
} else {
|
||||
cycle = cycleDaysSortedByDate.slice(0, cycleStartIndex + 1)
|
||||
cycleLength = startLocalDate.until(todayAsLocalDate, DAYS)
|
||||
}
|
||||
return cycle.length > maxCycleLength ? null : cycle
|
||||
console.log(cycleLength, maxCycleLength)
|
||||
return cycleLength > maxCycleLength ? null : cycle
|
||||
}
|
||||
|
||||
function getCycleForDay(dayOrDate) {
|
||||
function getCycleForDay(dayOrDate, todayDate) {
|
||||
const dateString = typeof dayOrDate === 'string' ? dayOrDate : dayOrDate.date
|
||||
const cycleStart = getLastMensesStartForDay(dateString)
|
||||
if (!cycleStart) return null
|
||||
return getCycleForCycleStartDay(cycleStart)
|
||||
return getCycleForCycleStartDay(cycleStart, todayDate)
|
||||
}
|
||||
|
||||
function isMensesStart(cycleDay) {
|
||||
|
||||
Reference in New Issue
Block a user