Shorten line lengths in cycle

This commit is contained in:
Julia Friesel
2018-08-02 10:47:06 +02:00
parent 63154be24a
commit a2c428e991
2 changed files with 21 additions and 10 deletions
+4 -3
View File
@@ -28,19 +28,20 @@ export default function config(opts) {
return day return day
}) })
const firstBleedingBeforeTargetDayIndex = withWrappedDates.findIndex(day => { // the index of the first bleeding day before the target day
const index = withWrappedDates.findIndex(day => {
return ( return (
day.wrappedDate.isEqual(targetDate) || day.wrappedDate.isEqual(targetDate) ||
day.wrappedDate.isBefore(targetDate) day.wrappedDate.isBefore(targetDate)
) )
}) })
if (firstBleedingBeforeTargetDayIndex < 0) { if (index < 0) {
withWrappedDates.forEach(day => delete day.wrappedDate) withWrappedDates.forEach(day => delete day.wrappedDate)
return null return null
} }
const prevBleedingDays = withWrappedDates.slice(firstBleedingBeforeTargetDayIndex) const prevBleedingDays = withWrappedDates.slice(index)
const lastMensesStart = prevBleedingDays.find((day, i) => { const lastMensesStart = prevBleedingDays.find((day, i) => {
return noBleedingDayWithinThreshold(day, prevBleedingDays.slice(i + 1)) return noBleedingDayWithinThreshold(day, prevBleedingDays.slice(i + 1))
+17 -7
View File
@@ -5,6 +5,10 @@ import cycleModule from '../lib/cycle'
const expect = chai.expect const expect = chai.expect
chai.use(dirtyChai) chai.use(dirtyChai)
function useBleedingDays(days) {
return cycleModule({ bleedingDaysSortedByDate: days }).getCycleDayNumber
}
describe('getCycleDay', () => { describe('getCycleDay', () => {
it('works for a simple example', () => { it('works for a simple example', () => {
const bleedingDays = [{ const bleedingDays = [{
@@ -23,7 +27,7 @@ describe('getCycleDay', () => {
value: 2 value: 2
} }
}] }]
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(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)
@@ -49,7 +53,7 @@ describe('getCycleDay', () => {
} }
}] }]
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(15) expect(result).to.eql(15)
}) })
@@ -73,7 +77,7 @@ describe('getCycleDay', () => {
}] }]
const targetDate = '2018-04-27' const targetDate = '2018-04-27'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(18) expect(result).to.eql(18)
}) })
@@ -87,7 +91,7 @@ describe('getCycleDay', () => {
}] }]
const targetDate = '2018-05-13' const targetDate = '2018-05-13'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(1) expect(result).to.eql(1)
}) })
@@ -96,7 +100,7 @@ describe('getCycleDay', () => {
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 = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.be.null() expect(result).to.be.null()
}) })
@@ -119,7 +123,10 @@ describe('getCycleDay', () => {
}] }]
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber const getCycleDayNumber = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
}).getCycleDayNumber
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8) expect(result).to.eql(8)
}) })
@@ -137,7 +144,10 @@ describe('getCycleDay', () => {
} }
}] }]
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber const getCycleDayNumber = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
}).getCycleDayNumber
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4) expect(result).to.eql(4)
}) })