Adds getTime function for bleedingPredictions reuse; minor style formatting
This commit is contained in:
+12
-11
@@ -179,13 +179,17 @@ export default class Home extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTimes(prediction) {
|
||||||
|
const todayDate = LocalDate.now()
|
||||||
|
const predictedBleedingStart = LocalDate.parse(prediction[0][0])
|
||||||
|
const predictedBleedingEnd = LocalDate.parse(prediction[0][ prediction[0].length - 1 ])
|
||||||
|
const daysToEnd = todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)
|
||||||
|
return { todayDate, predictedBleedingStart, predictedBleedingEnd, daysToEnd }
|
||||||
|
}
|
||||||
|
|
||||||
function determinePredictionText(bleedingPrediction) {
|
function determinePredictionText(bleedingPrediction) {
|
||||||
if (!bleedingPrediction.length) return predictLabels.noPrediction
|
if (!bleedingPrediction.length) return predictLabels.noPrediction
|
||||||
const todayDate = LocalDate.now()
|
const { todayDate, predictedBleedingStart, predictedBleedingEnd, daysToEnd } = getTimes(bleedingPrediction)
|
||||||
const predictedBleedingStart = LocalDate.parse(bleedingPrediction[0][0])
|
|
||||||
const predictedBleedingEnd = LocalDate.parse(
|
|
||||||
bleedingPrediction[0][ bleedingPrediction[0].length - 1 ]
|
|
||||||
)
|
|
||||||
if (todayDate.isBefore(predictedBleedingStart)) {
|
if (todayDate.isBefore(predictedBleedingStart)) {
|
||||||
return predictLabels.predictionInFuture(
|
return predictLabels.predictionInFuture(
|
||||||
todayDate.until(predictedBleedingStart, ChronoUnit.DAYS),
|
todayDate.until(predictedBleedingStart, ChronoUnit.DAYS),
|
||||||
@@ -194,10 +198,10 @@ function determinePredictionText(bleedingPrediction) {
|
|||||||
}
|
}
|
||||||
if (todayDate.isAfter(predictedBleedingEnd)) {
|
if (todayDate.isAfter(predictedBleedingEnd)) {
|
||||||
return predictLabels.predictionInPast(
|
return predictLabels.predictionInPast(
|
||||||
formatDateForShortText(predictedBleedingStart), formatDateForShortText(predictedBleedingEnd)
|
formatDateForShortText(predictedBleedingStart),
|
||||||
|
formatDateForShortText(predictedBleedingEnd)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const daysToEnd = todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)
|
|
||||||
if (daysToEnd === 0) {
|
if (daysToEnd === 0) {
|
||||||
return predictLabels.predictionStartedNoDaysLeft
|
return predictLabels.predictionStartedNoDaysLeft
|
||||||
} else if (daysToEnd === 1) {
|
} else if (daysToEnd === 1) {
|
||||||
@@ -209,16 +213,13 @@ function determinePredictionText(bleedingPrediction) {
|
|||||||
|
|
||||||
function getBleedingPredictionRange(prediction) {
|
function getBleedingPredictionRange(prediction) {
|
||||||
if (!prediction.length) return labels.unknown
|
if (!prediction.length) return labels.unknown
|
||||||
const todayDate = LocalDate.now()
|
const { todayDate, predictedBleedingStart, predictedBleedingEnd, daysToEnd } = getTimes(prediction)
|
||||||
const predictedBleedingStart = LocalDate.parse(prediction[0][0])
|
|
||||||
const predictedBleedingEnd = LocalDate.parse(prediction[0][ prediction[0].length - 1 ])
|
|
||||||
if (todayDate.isBefore(predictedBleedingStart)) {
|
if (todayDate.isBefore(predictedBleedingStart)) {
|
||||||
return `${todayDate.until(predictedBleedingStart, ChronoUnit.DAYS)}-${todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)}`
|
return `${todayDate.until(predictedBleedingStart, ChronoUnit.DAYS)}-${todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)}`
|
||||||
}
|
}
|
||||||
if (todayDate.isAfter(predictedBleedingEnd)) {
|
if (todayDate.isAfter(predictedBleedingEnd)) {
|
||||||
return labels.unknown
|
return labels.unknown
|
||||||
}
|
}
|
||||||
const daysToEnd = todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)
|
|
||||||
if (daysToEnd === 0) {
|
if (daysToEnd === 0) {
|
||||||
return '0'
|
return '0'
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user