I am developing a calender which is for menstrual cycle calculator ,I have to highlight the days for the following phase,they are
highlighting of days
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: http://jsfiddle.net/2sf4gfdr/