-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminus-8-day-rule.js
30 lines (26 loc) · 976 Bytes
/
minus-8-day-rule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { LocalDate } = require('js-joda')
const getNfpStatus = require('./index.js')
module.exports = function (previousCycles, secondarySymptom) {
const fhms = previousCycles
.map(cycle => {
const status = getNfpStatus({
cycle,
secondarySymptom,
excludePreOvu: true
})
if (status.temperatureShift) {
const day = status.temperatureShift.firstHighMeasurementDay
const firstCycleDayDate = LocalDate.parse(cycle[0].date)
const fhmDate = LocalDate.parse(day.date)
return fhmDate.compareTo(firstCycleDayDate) + 1
}
return null
})
.filter(val => typeof val === 'number')
const preOvuLength = Math.min(...fhms) - 8
// pre ovu length may only be lengthened if we have more than 12 previous fhms
// if pre ovu length is less than 5, it shortened even with fewer prev fhms
if (preOvuLength < 5) return preOvuLength
if (fhms.length >= 12) return preOvuLength
return null
}