Merge branch '342-bleeding-prediction-on-homescreen' into 'master'
Resolve "Bleeding prediction on homescreen" Closes #342 See merge request bloodyhealth/drip!202
This commit is contained in:
@@ -7,3 +7,7 @@ export default function (date) {
|
|||||||
const formattedDate = today.equals(dateToDisplay) ? 'today' : moment(date).format('MMMM Do YYYY')
|
const formattedDate = today.equals(dateToDisplay) ? 'today' : moment(date).format('MMMM Do YYYY')
|
||||||
return formattedDate.toLowerCase()
|
return formattedDate.toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatDateForShortText (date) {
|
||||||
|
return moment(date.toString()).format('dddd, MMMM Do')
|
||||||
|
}
|
||||||
+22
-18
@@ -16,6 +16,7 @@ import { getFertilityStatusForDay } from '../lib/sympto-adapter'
|
|||||||
import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles'
|
import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles'
|
||||||
import AppText from './app-text'
|
import AppText from './app-text'
|
||||||
import Button from './button'
|
import Button from './button'
|
||||||
|
import { formatDateForShortText } from './helpers/format-date'
|
||||||
|
|
||||||
const ShowMoreToggler = ({ isShowingMore, onToggle }) => {
|
const ShowMoreToggler = ({ isShowingMore, onToggle }) => {
|
||||||
const {height, width} = Dimensions.get('window')
|
const {height, width} = Dimensions.get('window')
|
||||||
@@ -178,25 +179,30 @@ export default class Home extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTimes(prediction) {
|
||||||
|
const todayDate = LocalDate.now()
|
||||||
|
const predictedBleedingStart = LocalDate.parse(prediction[0][0])
|
||||||
|
/* the range of predicted bleeding days can be either 3 or 5 */
|
||||||
|
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 bleedingStart = LocalDate.parse(bleedingPrediction[0][0])
|
if (todayDate.isBefore(predictedBleedingStart)) {
|
||||||
const bleedingEnd = LocalDate.parse(
|
|
||||||
bleedingPrediction[0][ bleedingPrediction[0].length - 1 ]
|
|
||||||
)
|
|
||||||
if (todayDate.isBefore(bleedingStart)) {
|
|
||||||
return predictLabels.predictionInFuture(
|
return predictLabels.predictionInFuture(
|
||||||
todayDate.until(bleedingStart, ChronoUnit.DAYS),
|
todayDate.until(predictedBleedingStart, ChronoUnit.DAYS),
|
||||||
todayDate.until(bleedingEnd, ChronoUnit.DAYS)
|
todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (todayDate.isAfter(bleedingEnd)) {
|
if (todayDate.isAfter(predictedBleedingEnd)) {
|
||||||
return predictLabels.predictionInPast(
|
return predictLabels.predictionInPast(
|
||||||
bleedingStart.toString(), bleedingEnd.toString()
|
formatDateForShortText(predictedBleedingStart),
|
||||||
|
formatDateForShortText(predictedBleedingEnd)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const daysToEnd = todayDate.until(bleedingEnd, ChronoUnit.DAYS)
|
|
||||||
if (daysToEnd === 0) {
|
if (daysToEnd === 0) {
|
||||||
return predictLabels.predictionStartedNoDaysLeft
|
return predictLabels.predictionStartedNoDaysLeft
|
||||||
} else if (daysToEnd === 1) {
|
} else if (daysToEnd === 1) {
|
||||||
@@ -208,14 +214,12 @@ 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 bleedingStart = LocalDate.parse(prediction[0][0])
|
if (todayDate.isBefore(predictedBleedingStart)) {
|
||||||
const bleedingEnd = LocalDate.parse(prediction[0][ prediction[0].length - 1 ])
|
return `${todayDate.until(predictedBleedingStart, ChronoUnit.DAYS)}-${todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)}`
|
||||||
if (todayDate.isBefore(bleedingStart)) {
|
|
||||||
return `${todayDate.until(bleedingStart, ChronoUnit.DAYS)}-${todayDate.until(bleedingEnd, ChronoUnit.DAYS)}`
|
|
||||||
}
|
}
|
||||||
if (todayDate.isAfter(bleedingEnd)) {
|
if (todayDate.isAfter(predictedBleedingEnd)) {
|
||||||
return labels.unknown
|
return labels.unknown
|
||||||
}
|
}
|
||||||
return '0'
|
return (daysToEnd === 0 ? '0' : `0 - ${daysToEnd}`)
|
||||||
}
|
}
|
||||||
@@ -58,9 +58,9 @@ export default function setupNotifications(navigate) {
|
|||||||
function setupPeriodReminder() {
|
function setupPeriodReminder() {
|
||||||
const bleedingPrediction = cycleModule().getPredictedMenses()
|
const bleedingPrediction = cycleModule().getPredictedMenses()
|
||||||
if (bleedingPrediction.length > 0) {
|
if (bleedingPrediction.length > 0) {
|
||||||
const bleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
|
const predictedBleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
|
||||||
// 3 days before and at 6 am
|
// 3 days before and at 6 am
|
||||||
const reminderDate = bleedingStart
|
const reminderDate = predictedBleedingStart
|
||||||
.subtract(3, 'days')
|
.subtract(3, 'days')
|
||||||
.hours(6)
|
.hours(6)
|
||||||
.minutes(0)
|
.minutes(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user