madhavan madhavan - 1 year ago 146
Javascript Question

Menstrual Tracking Calendar

I am developing a calender which is for menstrual cycle calculator ,I have to highlight the days for the following phase,they are

  1. Bleeding Days

  2. Fertile Phase

  3. Ovulation Day

Data which i have for the process

  1. The user will choose the date when period starts

  2. The menstrual range by default of 28 days

Process by the data

With the date of period started and the cycle range,the above mentioned formulas will be applied

for calculating three different range of dates

Using the range of dates,the highlighting of dates will be applied for the year and upcoming years

The calculation steps for all the ranges

Bleeding Date Calculation

Assume that user selected date as "a"
Assume the default period cycle as "X"

bleeding days=x + 3 days

Fertile Phase Calcultaion

Fertile Phase I

the formula provides the end date of the phase 1

phase I ranges from date selected and the end date of phase 1


b =[{a +(x-1)-19}]

Fertile Phase II


Fertile Phase

Range from (b+1) till (c-1) is fertile phase range

Ovulation Day

Particular Date=[(b-1) +{(c-b)/2}]

i am using jqm calendar

Problem is: I can't figure out how to replicate the
highlighting of days
to all dates based on the calculation for all months

Answer Source

You don't have to work out all dates for all months, you only really need to work out the next two events on each update of the calendar (since you may have up to two sets of events in one month but never more). When the user navigates to the next month, you can calculate the events for that month "on the fly".

You've already got the time spans between events from which to calculate future events. I've simplified your formulae to this:

var periodCycleDays = 28;
var fertilePhaseStart = periodCycleDays - 20;
var fertilePhaseEnd = periodCycleDays - 11;
var ovulation = (fertilePhaseStart-1) + (fertilePhaseEnd - fertilePhaseStart)/2;

With this, given an initial date, you can calculate the future events for any given month. All you need to do is work out how many cycles have passed between the initial event and the month that you're looking at. Then simply multiply all of your event time spans (variables above) by the number of passed cycles and add that number of days onto the initial date.

Here's an demo of how you might do this: