Add isMensesStart

This commit is contained in:
Julia Friesel
2018-10-23 16:24:17 +02:00
parent 1b20658eed
commit 2b2e24bb5c
2 changed files with 163 additions and 1 deletions
+21 -1
View File
@@ -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
}
}