Add comments and rename things for clarity
This commit is contained in:
+12
-3
@@ -89,6 +89,8 @@ export default function config(opts) {
|
||||
if (noBleedingDayWithinThresholdBefore(cycleDay)) return true
|
||||
return false
|
||||
|
||||
// checks that there are no relevant bleeding days before
|
||||
// the input cycleDay (returns boolean)
|
||||
function noBleedingDayWithinThresholdBefore(cycleDay) {
|
||||
const localDate = LocalDate.parse(cycleDay.date)
|
||||
const threshold = localDate.minusDays(maxBreakInBleeding + 1).toString()
|
||||
@@ -101,6 +103,9 @@ export default function config(opts) {
|
||||
}
|
||||
}
|
||||
|
||||
// returns all bleeding days that belong to one menses directly following
|
||||
// the cycle day. used to set or clear new cycle starts when the target day
|
||||
// changes
|
||||
function getMensesDaysRightAfter(cycleDay) {
|
||||
const bleedingDays = bleedingDaysSortedByDate
|
||||
.filter(d => !d.bleeding.exclude)
|
||||
@@ -110,6 +115,9 @@ export default function config(opts) {
|
||||
})
|
||||
return recurse(cycleDay, firstFollowingBleedingDayIndex, [])
|
||||
|
||||
// we look at the current bleeding day as well as the next, and decide
|
||||
// whether they belong to one menses. if they do, we collect them, once
|
||||
// they don't, we're done
|
||||
function recurse(day, nextIndex, mensesDays) {
|
||||
const next = bleedingDays[nextIndex]
|
||||
if (!next) return mensesDays
|
||||
@@ -118,10 +126,11 @@ export default function config(opts) {
|
||||
return recurse(next, nextIndex + 1, mensesDays)
|
||||
}
|
||||
|
||||
function isWithinThreshold(cycleDay, nextCycleDay) {
|
||||
const localDate = LocalDate.parse(cycleDay.date)
|
||||
// checks whether the two days belong to one menses episode
|
||||
function isWithinThreshold(bleedingDay, nextBleedingDay) {
|
||||
const localDate = LocalDate.parse(bleedingDay.date)
|
||||
const threshold = localDate.plusDays(maxBreakInBleeding + 1).toString()
|
||||
return nextCycleDay.date <= threshold
|
||||
return nextBleedingDay.date <= threshold
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user