Currently, the app has "orphaned" cycle records when the user adds overlapping period days. This allows for cycles of < 5 days and incorrectly tagged cycle_days.
Reproducible Example
Create a cycle whose period is from Sep 27 - Oct 1
Create a cycle whose period is from Sep 28 - Oct 1
You will have a cycle of 1 day (but records in cycle_days remains the same because the length of prevCycleDays is zero)
Expected behavior
The app automatically notices that there is a cycle with overlapping period and adjusts the previous and/or next cycle's dates (including cycle_days) accordingly.
Potential Code to Rewrite
File: @/db/controllers/cycles.ts
// Check if the next cycle exists
const nextCycle: Cycle[] = await getNextCycle(startDayjsUnix);
// If yes, use that as the current cycle's endDate
// ^^^ @TODO: WRONG! THIS MAKES IT POSSIBLE TO HAVE CYCLES OF < 5 DAYS!
// SHOULD CHECK IF nextCycle[0].startDate < startDayjs.add(periodLength, "day").valueOf()
if (nextCycle && nextCycle.length == 1 && nextCycle[0].startDate) {
const thisCycleLength = Math.round(
(nextCycle[0].startDate - startDayjsUnix) / NUM_MS_PER_DAY
);
cycleDetails.cycleLength = thisCycleLength;
cycleDetails.endDate = nextCycle[0].startDate - NUM_MS_PER_DAY;
} else {
cycleDetails.endDate = startDayjs.add(cycleLength, "day").valueOf();
cycleDetails.cycleLength = cycleLength;
}
Description
Currently, the app has "orphaned"
cycle
records when the user adds overlapping period days. This allows for cycles of < 5 days and incorrectly tagged cycle_days.Reproducible Example
cycle
of 1 day (but records incycle_days
remains the same because the length ofprevCycleDays
is zero)Expected behavior
The app automatically notices that there is a cycle with overlapping period and adjusts the previous and/or next cycle's dates (including cycle_days) accordingly.
Potential Code to Rewrite
File:
@/db/controllers/cycles.ts