Accept previousCycles as array

This commit is contained in:
Julia Friesel
2018-07-11 14:14:42 +02:00
parent 9e645ddd8e
commit 19e880183e
3 changed files with 55 additions and 32 deletions
+16 -7
View File
@@ -1,13 +1,20 @@
import { LocalDate } from "js-joda"
export default function(cycle) {
export default function(cycle, previousCycles) {
// TODO handle no previous cycles
let preOvuPhaseLength = 5
//TODO make sure it handles weird cases like fhm < 9
const minus8DayRuleResult = apply8DayRule(previousCycles)
if (minus8DayRuleResult) preOvuPhaseLength = minus8DayRuleResult
const startDate = LocalDate.parse(cycle[0].date)
const fiveDayEndDate = startDate.plusDays(4).toString()
const fiveDayRuleDays = cycle.slice(0, 5).filter(d => d.date <= fiveDayEndDate)
const preOvulatoryDays = getDaysUntilFertileMucus(fiveDayRuleDays)
const preOvuPhaseEndDate = startDate.plusDays(preOvuPhaseLength - 1).toString()
const maybePreOvuDays = cycle.slice(0, 5).filter(d => d.date <= preOvuPhaseEndDate)
const preOvulatoryDays = getDaysUntilFertileMucus(maybePreOvuDays)
let endDate
if (preOvulatoryDays.length === fiveDayRuleDays.length) {
endDate = fiveDayEndDate
if (preOvulatoryDays.length === maybePreOvuDays.length) {
endDate = preOvuPhaseEndDate
} else {
endDate = preOvulatoryDays[preOvulatoryDays.length - 1].date
}
@@ -29,4 +36,6 @@ function getDaysUntilFertileMucus(days) {
return days.slice(0, firstFertileMucusDayIndex)
}
return days
}
}
function apply8DayRule() {}