changs output of getpredictedmenses, adds days to calendar

This commit is contained in:
tina
2018-08-23 17:28:53 +02:00
parent 497a3a3ff5
commit e047440068
3 changed files with 119 additions and 64 deletions
+12 -8
View File
@@ -163,12 +163,11 @@ export default function config(opts) {
function getPredictedMenses() {
const allMensesStarts = getAllMensesStarts()
const atLeastOneCycle = allMensesStarts.length > 1
if (!atLeastOneCycle ||
allMensesStarts.length < minCyclesForPrediction
) {
return {}
return []
}
const cycleLengths = getCycleLength(allMensesStarts)
const cycleInfo = getCycleLengthStats(cycleLengths)
@@ -181,15 +180,20 @@ export default function config(opts) {
} else {
periodStartVariation = 2
}
var lastStart = allMensesStarts[0]
if (periodDistance - 5 < periodStartVariation) { // otherwise predictions overlap
return []
}
let lastStart = LocalDate.parse(allMensesStarts[0])
const predictedMenses = []
for (let i = 0; i < 3; i++) {
lastStart = LocalDate.parse(lastStart).plusDays(periodDistance).toString()
const nextPredictedRange = {
'startDate': LocalDate.parse(lastStart).minusDays(periodStartVariation).toString(),
'endDate': LocalDate.parse(lastStart).plusDays(periodStartVariation).toString()
lastStart = lastStart.plusDays(periodDistance)
const nextPredictedDates = [lastStart.toString()]
for (let j = 0; j < periodStartVariation; j++) {
nextPredictedDates.push(lastStart.minusDays(j+1).toString())
nextPredictedDates.push(lastStart.plusDays(j+1).toString())
}
predictedMenses.push(nextPredictedRange)
nextPredictedDates.sort()
predictedMenses.push(nextPredictedDates)
}
return predictedMenses
}