Welcome Guest, Not a member yet? Register   Sign In
Calendar determining work shifts
#1

[eluser]fergp25[/eluser]
This isn't so much a Codeigniter problem as it is a general logic problem.

I'm building a calendar to track work details. All is going fine and I'm virtually done with it. However, the customer wants me to add in a seemingly simple detail.

On each day of the week on the calendar, I need to determine if the current user is in Shift A or Shift B.

Shifts are as follows.

Beginning on 4/7/2013 Shift A will work 5 days on, 4 days off, 5 days on, 4 days off, 5 days on, 5 days off (repeats forever)
Beginning on 4/21/2013 Shift B will work 5 days on, 4 days off, 5 days on, 4 days off, 5 days on, 5 days off (repeats forever)

Same on/off schedule for both shifts, however they start on different days. I need to determine what shift will work on what day.
#2

[eluser]micfai[/eluser]
You know the start dates so you can generate the current month's worth of schedules. We will call 5 days on, 4 days off, 5 days on, 4 days off, 5 days on, 5 days off one cycle. Each cycle is 28 days.

For instance you could take today's date and find out how many days its been since 4/7/2013. Divide that number by 28, round down to the nearest whole number and multiply by 28. take your first number and subtract the number you just got from multiplication. This will give you a number less than 28 which tells you what day in the cycle you are on.

Example: Today is 37 days past 4/7. 37/28 = 1.32. round down to 1. 28*1 = 28. 37-28 = 9. 9 is the day in the current cycle which is day 4 of the 4 days off. The next day would be 5 days on 4 days off etc.
#3

[eluser]fergp25[/eluser]
Thanks! That makes sense, I'll give it a try!
#4

[eluser]fergp25[/eluser]
Thanks, that worked!
#5

[eluser]micfai[/eluser]
Glad I could be of help!




Theme © iAndrew 2016 - Forum software by © MyBB