Add isMensesStart
This commit is contained in:
+21
-1
@@ -133,6 +133,25 @@ export default function config(opts) {
|
||||
}
|
||||
}
|
||||
|
||||
function isMensesStart(cycleDay) {
|
||||
if (!cycleDay.bleeding || cycleDay.bleeding.exclude) return false
|
||||
const bleedingDays = bleedingDaysSortedByDate
|
||||
if (noBleedingDayWithinThreshold(cycleDay)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
function noBleedingDayWithinThreshold(day) {
|
||||
const localDate = LocalDate.parse(day.date)
|
||||
const threshold = localDate.minusDays(maxBreakInBleeding + 1).toString()
|
||||
const index = bleedingDays.findIndex(day => day.date === cycleDay.date)
|
||||
const previousBleedingDays = bleedingDays.slice(index + 1)
|
||||
return !previousBleedingDays.some(day => {
|
||||
return day.date >= threshold && !day.bleeding.exclude
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getCycleLength(cycleStartDates) {
|
||||
const cycleLengths = []
|
||||
for (let i = 0; i < cycleStartDates.length - 1; i++) {
|
||||
@@ -188,6 +207,7 @@ export default function config(opts) {
|
||||
getCyclesBefore,
|
||||
getAllMensesStarts,
|
||||
getCycleLength,
|
||||
getPredictedMenses
|
||||
getPredictedMenses,
|
||||
isMensesStart
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user