I am doing a calender page to display day, night and off days of shift work.
The schedule goes like this: 7 days off, 4 nights, 3 days off, 1 day off, 3 nights, 3 days off, 4 days and then the 28 day cycle starts all over again. The cycle always starts on Friday.
There are 4 different crews: each one starts a week after the other.
So I have a sql table that just has the month, day and year of the first 28 day cycle of the first crew's 7 off and I suck that into a collection and add the fields to calculate the other crews' starting 7 off.
The calender has a different color to show whether its your day off, nights, days. So I go through the list and use the first day of the cycle as an index into an array of:
static int[] DaysArray = new int[28] {0,0,0,0,0,0,0,2,2,2,2,0,0,0,1,1,1,0,2,2,2,0,0,0,1,1,1,1}; // 0 - day off, 1 - days, 2 - nights
All I'm interested in is determining at what point into the 28 day cycle the start of the month is and I just color in the rest of the days with the appropriate color. Here's the routine I'm struggling with:
protected int GetDayNightOff(int day)
{
day--;
day -= 28;
day = Math.Abs(day);
day--;
return DaysArray[day];
}
If the first day of the cycle falls on the 1st, then I want to show the starting color using index 0; the 2nd: index 27; 3rd: index 26 and so on. I know there's a simple solution but I just can't seem to get my head around it.
Hope someone could help, it would be greatly appreciated.