Simplify cycle start detection funtions
This commit is contained in:
+1
-33
@@ -177,36 +177,6 @@ export default function config(opts) {
|
||||
}
|
||||
|
||||
|
||||
// TODO this also needs a test
|
||||
function maybeSetNewCycleStart(oldCycleDay, newValue) {
|
||||
// if a bleeding value is deleted, we need to check if
|
||||
// there are any following bleeding days and if the
|
||||
// next one of them is now a cycle start
|
||||
|
||||
// in order to get the menses days, the cycle day in question still
|
||||
// has to have a bleeding value, so we get those days first and only
|
||||
// then update the cycle day
|
||||
const mensesDaysAfter = getMensesDaysRightAfter(oldCycleDay)
|
||||
oldCycleDay.bleeding = newValue
|
||||
oldCycleDay.isCycleStart = false
|
||||
|
||||
if (!mensesDaysAfter.length) return
|
||||
|
||||
const nextOne = mensesDaysAfter[mensesDaysAfter.length - 1]
|
||||
if (isMensesStart(nextOne)) {
|
||||
nextOne.isCycleStart = true
|
||||
}
|
||||
}
|
||||
|
||||
function maybeClearOldCycleStartsInThisMenses(cycleDay) {
|
||||
// if we have a new bleeding day, we need to clear the
|
||||
// menses start marker from all following days of this
|
||||
// menses that may have been marked as start before
|
||||
const mensesDaysAfter = getMensesDaysRightAfter(cycleDay)
|
||||
mensesDaysAfter.forEach(day => day.isCycleStart = false)
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
getCycleDayNumber,
|
||||
getCycleForDay,
|
||||
@@ -215,8 +185,6 @@ export default function config(opts) {
|
||||
getAllCycleLengths,
|
||||
getPredictedMenses,
|
||||
isMensesStart,
|
||||
getMensesDaysRightAfter,
|
||||
maybeSetNewCycleStart,
|
||||
maybeClearOldCycleStartsInThisMenses
|
||||
getMensesDaysRightAfter
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user