Get previous cycles before detecting fertility status

This commit is contained in:
Julia Friesel
2018-07-13 11:30:54 +02:00
parent 8a8b131064
commit 85e2703b2f
4 changed files with 175 additions and 60 deletions
+27 -3
View File
@@ -1,4 +1,5 @@
import * as joda from 'js-joda'
const LocalDate = joda.LocalDate
export default function config(opts) {
@@ -49,14 +50,16 @@ export default function config(opts) {
return !previousBleedingDays.some(({ wrappedDate }) => wrappedDate.equals(periodThreshold) || wrappedDate.isAfter(periodThreshold))
}
withWrappedDates.forEach(day => delete day.wrappedDate)
return lastPeriodStart
}
function getCycleDayNumber(targetDateString) {
const lastMensesStart = getLastMensesStart(targetDateString)
if (!lastMensesStart) return null
const targetDate = joda.LocalDate.parse(targetDateString)
const diffInDays = lastMensesStart.wrappedDate.until(targetDate, joda.ChronoUnit.DAYS)
const targetDate = LocalDate.parse(targetDateString)
const lastMensesLocalDate = LocalDate.parse(lastMensesStart.date)
const diffInDays = lastMensesLocalDate.until(targetDate, joda.ChronoUnit.DAYS)
// cycle starts at day 1
return diffInDays + 1
@@ -73,15 +76,36 @@ export default function config(opts) {
function getCycleDaysBeforeDay(targetDateString) {
const firstCycleDay = getLastMensesStart(targetDateString)
if (!firstCycleDay) return null
return cycleDaysSortedByDate.filter(({date}) => {
return date >= firstCycleDay.date && date <= targetDateString
})
}
function getPreviousCycles(targetCycleStartDay) {
let previousCycleStartIndex = cycleDaysSortedByDate.indexOf(targetCycleStartDay)
const cycles = []
while (previousCycleStartIndex < cycleDaysSortedByDate.length - 1) {
const prevDate = cycleDaysSortedByDate[previousCycleStartIndex + 1].date
const cycleStart = getLastMensesStart(prevDate)
if (!cycleStart) break
const cycleStartIndex = cycleDaysSortedByDate.indexOf(cycleStart)
const lastDayInCycle = previousCycleStartIndex + 1
const cycle = cycleDaysSortedByDate.slice(lastDayInCycle, cycleStartIndex + 1)
cycles.push(cycle)
previousCycleStartIndex = cycleStartIndex
}
return cycles
}
return {
getCycleDayNumber,
getLastMensesStart,
getPreviousTemperaturesInCycle,
getCycleDaysBeforeDay
getCycleDaysBeforeDay,
getPreviousCycles
}
}