Chore/prettify for joda

This commit is contained in:
Sofiya Tepikin
2022-07-27 17:57:41 +00:00
parent 1bd00a7ec2
commit 4e8c0080e6
6 changed files with 130 additions and 128 deletions
+28 -29
View File
@@ -30,7 +30,9 @@ export default function config(opts) {
}
function getLastMensesStartForDay(targetDateString) {
return cycleStartsSortedByDate.find(start => start.date <= targetDateString)
return cycleStartsSortedByDate.find(
(start) => start.date <= targetDateString
)
}
function getCycleDayNumber(targetDateString) {
@@ -55,25 +57,25 @@ export default function config(opts) {
}
function getCyclesBefore(targetCycleStartDay) {
const startFromHere = cycleStartsSortedByDate.findIndex(start => {
const startFromHere = cycleStartsSortedByDate.findIndex((start) => {
return start.date < targetCycleStartDay.date
})
if (startFromHere < 0) return null
return cycleStartsSortedByDate
.slice(startFromHere)
.map(start => getCycleByStartDay(start))
// filter the ones exceeding maxCycleLength, those are null
.filter(cycle => cycle)
return (
cycleStartsSortedByDate
.slice(startFromHere)
.map((start) => getCycleByStartDay(start))
// filter the ones exceeding maxCycleLength, those are null
.filter((cycle) => cycle)
)
}
function findIndexOfDay(day, daysSortedByDate) {
return daysSortedByDate.findIndex(d => d.date === day.date)
return daysSortedByDate.findIndex((d) => d.date === day.date)
}
function getNextCycleStartDay(startDay, cycleStartsSortedByDate) {
const cycleStartIndex = findIndexOfDay(
startDay,
cycleStartsSortedByDate)
const cycleStartIndex = findIndexOfDay(startDay, cycleStartsSortedByDate)
return cycleStartsSortedByDate[cycleStartIndex - 1]
}
@@ -82,8 +84,7 @@ export default function config(opts) {
}
function getCycleLength(startDate, endDate) {
return LocalDate.parse(startDate)
.until(LocalDate.parse(endDate), DAYS)
return LocalDate.parse(startDate).until(LocalDate.parse(endDate), DAYS)
}
function isValidCycle(startDate, endDate) {
@@ -109,19 +110,16 @@ export default function config(opts) {
}
if (isValidCycle(startDay.date, cycleEndDate)) {
const cycleStartIndex = findIndexOfDay(
startDay,
cycleDaysSortedByDate
)
return cycleDaysSortedByDate
.slice(cycleEndIndex, cycleStartIndex + 1)
const cycleStartIndex = findIndexOfDay(startDay, cycleDaysSortedByDate)
return cycleDaysSortedByDate.slice(cycleEndIndex, cycleStartIndex + 1)
}
return null
}
function getCycleForDay(dayOrDate, todayDate) {
const dateString = typeof dayOrDate === 'string' ? dayOrDate : dayOrDate.date
const dateString =
typeof dayOrDate === 'string' ? dayOrDate : dayOrDate.date
const cycleStart = getLastMensesStartForDay(dateString)
if (!cycleStart) return null
return getCycleByStartDay(cycleStart, todayDate)
@@ -138,9 +136,9 @@ export default function config(opts) {
const localDate = LocalDate.parse(cycleDay.date)
const threshold = localDate.minusDays(maxBreakInBleeding + 1).toString()
const bleedingDays = bleedingDaysSortedByDate
const index = bleedingDays.findIndex(day => day.date === cycleDay.date)
const index = bleedingDays.findIndex((day) => day.date === cycleDay.date)
const candidates = bleedingDays.slice(index + 1)
return !candidates.some(day => {
return !candidates.some((day) => {
return day.date >= threshold && !day.bleeding.exclude
})
}
@@ -151,9 +149,9 @@ export default function config(opts) {
// changes
function getMensesDaysRightAfter(cycleDay) {
const bleedingDays = bleedingDaysSortedByDate
.filter(d => !d.bleeding.exclude)
.filter((d) => !d.bleeding.exclude)
.reverse()
const firstFollowingBleedingDayIndex = bleedingDays.findIndex(day => {
const firstFollowingBleedingDayIndex = bleedingDays.findIndex((day) => {
return day.date > cycleDay.date
})
return recurse(cycleDay, firstFollowingBleedingDayIndex, [])
@@ -179,13 +177,13 @@ export default function config(opts) {
function getAllCycleLengths() {
return cycleStartsSortedByDate
.map(day => LocalDate.parse(day.date))
.map((day) => LocalDate.parse(day.date))
.map((cycleStart, i, startsAsLocalDates) => {
if (i === cycleStartsSortedByDate.length - 1) return null
const prevCycleStart = startsAsLocalDates[i + 1]
return prevCycleStart.until(cycleStart, DAYS)
})
.filter(length => length && length <= maxCycleLength)
.filter((length) => length && length <= maxCycleLength)
}
function getPredictedMenses() {
@@ -198,12 +196,14 @@ export default function config(opts) {
let periodStartVariation
if (cycleInfo.stdDeviation === null) {
periodStartVariation = 2
} else if (cycleInfo.stdDeviation < 1.5) { // threshold is chosen a little arbitrarily
} else if (cycleInfo.stdDeviation < 1.5) {
// threshold is chosen a little arbitrarily
periodStartVariation = 1
} else {
periodStartVariation = 2
}
if (periodDistance - 5 < periodStartVariation) { // otherwise predictions overlap
if (periodDistance - 5 < periodStartVariation) {
// otherwise predictions overlap
return []
}
const allMensesStarts = cycleStartsSortedByDate
@@ -222,7 +222,6 @@ export default function config(opts) {
return predictedMenses
}
return {
getCycleDayNumber,
getCycleForDay,