Change getCycleDayNumber signature and some PR improvements
This commit is contained in:
+2
-3
@@ -11,9 +11,8 @@ import { saveBleeding } from './db'
|
|||||||
import { formatDateForViewHeader } from './format'
|
import { formatDateForViewHeader } from './format'
|
||||||
import { bleeding as labels } from './labels'
|
import { bleeding as labels } from './labels'
|
||||||
import cycleDayModule from './get-cycle-day-number'
|
import cycleDayModule from './get-cycle-day-number'
|
||||||
import { bleedingDaysSortedByDate } from './db'
|
|
||||||
|
|
||||||
const getCycleDay = cycleDayModule(bleedingDaysSortedByDate)
|
const getCycleDayNumber = cycleDayModule()
|
||||||
|
|
||||||
export default class Bleeding extends Component {
|
export default class Bleeding extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -43,7 +42,7 @@ export default class Bleeding extends Component {
|
|||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
|
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
|
||||||
<Text>Cycle day {getCycleDay(day.date)}</Text>
|
<Text>Cycle day {getCycleDayNumber(day.date)}</Text>
|
||||||
<Text>Bleeding</Text>
|
<Text>Bleeding</Text>
|
||||||
<RadioForm
|
<RadioForm
|
||||||
radio_props={bleedingRadioProps}
|
radio_props={bleedingRadioProps}
|
||||||
|
|||||||
+4
-4
@@ -10,14 +10,14 @@ import { bleeding as labels} from './labels'
|
|||||||
import cycleDayModule from './get-cycle-day-number'
|
import cycleDayModule from './get-cycle-day-number'
|
||||||
import { bleedingDaysSortedByDate } from './db'
|
import { bleedingDaysSortedByDate } from './db'
|
||||||
|
|
||||||
const getCycleDay = cycleDayModule(bleedingDaysSortedByDate)
|
const getCycleDayNumber = cycleDayModule()
|
||||||
|
|
||||||
export default class DayView extends Component {
|
export default class DayView extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.cycleDay = props.navigation.state.params.cycleDay
|
this.cycleDay = props.navigation.state.params.cycleDay
|
||||||
this.state = {
|
this.state = {
|
||||||
cycleDayNumber: getCycleDay(this.cycleDay.date),
|
cycleDayNumber: getCycleDayNumber(this.cycleDay.date),
|
||||||
}
|
}
|
||||||
bleedingDaysSortedByDate.addListener(setStateWithCurrentCycleDayNumber.bind(this))
|
bleedingDaysSortedByDate.addListener(setStateWithCurrentCycleDayNumber.bind(this))
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ export default class DayView extends Component {
|
|||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
|
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
|
||||||
<Text>Cycle day {getCycleDay(day.date)}</Text>
|
<Text>Cycle day {getCycleDayNumber(day.date)}</Text>
|
||||||
<Text style={styles.welcome}>{bleedingLabel}</Text>
|
<Text style={styles.welcome}>{bleedingLabel}</Text>
|
||||||
<Button
|
<Button
|
||||||
onPress={() => navigate('bleeding', { cycleDay: day })}
|
onPress={() => navigate('bleeding', { cycleDay: day })}
|
||||||
@@ -53,6 +53,6 @@ export default class DayView extends Component {
|
|||||||
|
|
||||||
function setStateWithCurrentCycleDayNumber() {
|
function setStateWithCurrentCycleDayNumber() {
|
||||||
this.setState({
|
this.setState({
|
||||||
cycleDayNumber: getCycleDay(this.cycleDay.date)
|
cycleDayNumber: getCycleDayNumber(this.cycleDay.date)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
import * as joda from 'js-joda'
|
import * as joda from 'js-joda'
|
||||||
|
import { bleedingDaysSortedByDate as bleedingDaysSortedByDateView} from './db'
|
||||||
|
|
||||||
const LocalDate = joda.LocalDate
|
const LocalDate = joda.LocalDate
|
||||||
|
|
||||||
export default function config(bleedingDaysSortedByDateView, opts) {
|
export default function config(opts = {}) {
|
||||||
opts = opts || {
|
const bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || bleedingDaysSortedByDateView
|
||||||
maxBreakInBleeding: 1
|
const maxBreakInBleeding = opts.maxBreakInBleeding || 1
|
||||||
}
|
|
||||||
|
|
||||||
return function getCycleDayNumber(targetDateString) {
|
return function getCycleDayNumber(targetDateString) {
|
||||||
const targetDate = LocalDate.parse(targetDateString)
|
const targetDate = LocalDate.parse(targetDateString)
|
||||||
const withWrappedDates = bleedingDaysSortedByDateView
|
const withWrappedDates = bleedingDaysSortedByDate
|
||||||
.filter(day => !day.bleeding.exclude)
|
.filter(day => !day.bleeding.exclude)
|
||||||
.map(day => {
|
.map(day => {
|
||||||
day.wrappedDate = LocalDate.parse(day.date)
|
day.wrappedDate = LocalDate.parse(day.date)
|
||||||
@@ -21,7 +21,7 @@ export default function config(bleedingDaysSortedByDateView, opts) {
|
|||||||
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex)
|
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex)
|
||||||
|
|
||||||
const lastPeriodStart = previousBleedingDays.find((day, i) => {
|
const lastPeriodStart = previousBleedingDays.find((day, i) => {
|
||||||
return thereIsNoPreviousBleedingDayWithinTheThreshold(day, previousBleedingDays.slice(i + 1), opts.maxBreakInBleeding)
|
return thereIsNoPreviousBleedingDayWithinTheThreshold(day, previousBleedingDays.slice(i + 1), maxBreakInBleeding)
|
||||||
})
|
})
|
||||||
|
|
||||||
const diffInDays = lastPeriodStart.wrappedDate.until(targetDate, joda.ChronoUnit.DAYS)
|
const diffInDays = lastPeriodStart.wrappedDate.until(targetDate, joda.ChronoUnit.DAYS)
|
||||||
|
|||||||
@@ -9,13 +9,12 @@ import cycleDayModule from './get-cycle-day-number'
|
|||||||
import { bleedingDaysSortedByDate, deleteAll } from './db'
|
import { bleedingDaysSortedByDate, deleteAll } from './db'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
|
|
||||||
const getCycleDayNumber = cycleDayModule(bleedingDaysSortedByDate)
|
const getCycleDayNumber = cycleDayModule()
|
||||||
|
|
||||||
export default class Home extends Component {
|
export default class Home extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const now = new Date()
|
this.todayDateString = LocalDate.now().toString()
|
||||||
this.todayDateString = LocalDate.of(now.getFullYear(), now.getMonth() + 1, now.getDate()).toString()
|
|
||||||
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe('getCycleDay', () => {
|
|||||||
value: 2
|
value: 2
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
|
||||||
const targetDate = '2018-05-17'
|
const targetDate = '2018-05-17'
|
||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.eql(9)
|
expect(result).to.eql(9)
|
||||||
@@ -50,7 +50,7 @@ describe('getCycleDay', () => {
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
const targetDate = '2018-05-17'
|
const targetDate = '2018-05-17'
|
||||||
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
|
||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.eql(15)
|
expect(result).to.eql(15)
|
||||||
})
|
})
|
||||||
@@ -74,7 +74,7 @@ describe('getCycleDay', () => {
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
const targetDate = '2018-04-27'
|
const targetDate = '2018-04-27'
|
||||||
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
|
||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.eql(18)
|
expect(result).to.eql(18)
|
||||||
})
|
})
|
||||||
@@ -84,14 +84,14 @@ describe('getCycleDay returns null', () => {
|
|||||||
it('if there are no bleeding days', function () {
|
it('if there are no bleeding days', function () {
|
||||||
const bleedingDays = []
|
const bleedingDays = []
|
||||||
const targetDate = '2018-05-17'
|
const targetDate = '2018-05-17'
|
||||||
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
|
||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.be.null()
|
expect(result).to.be.null()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getCycleDay with cycle thresholds', () => {
|
describe('getCycleDay with cycle thresholds', () => {
|
||||||
const opts = { maxBreakInBleeding: 3 }
|
const maxBreakInBleeding = 3
|
||||||
|
|
||||||
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
|
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
|
||||||
const bleedingDays = [{
|
const bleedingDays = [{
|
||||||
@@ -107,7 +107,7 @@ describe('getCycleDay with cycle thresholds', () => {
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
const targetDate = '2018-05-17'
|
const targetDate = '2018-05-17'
|
||||||
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays, opts)
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding })
|
||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.eql(8)
|
expect(result).to.eql(8)
|
||||||
})
|
})
|
||||||
@@ -125,7 +125,7 @@ describe('getCycleDay with cycle thresholds', () => {
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
const targetDate = '2018-05-17'
|
const targetDate = '2018-05-17'
|
||||||
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays, opts)
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding })
|
||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.eql(4)
|
expect(result).to.eql(4)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user