I need to program a shift schedule for three shift in a four-brigade system. Each shift lasts eight hours. First shift start at 6 am. Second shift start at 2 pm. Third shift start at 10 pm. Each cycle has four days and 48 hours break.
The table below shows how is the schedule for January 20019.
"W" means a day off.
I would write a function which gets an argument date and number of shift and returns which brigade has a shift.
For example:
getBrigadeNumber('2019-01-27',1); // should return 'III' for schedule above
I completely don't have an idea how it writes.
I"ll write it in VBA, but I know php as well,
I will be grateful for any advice.
At first look the problem seems difficult - algorithm for three-shift schedule, but when you realize that the shifts are some patterns and these patterns doesn't change in time, than the problem starts to look very easy.
The idea to "Keeps first month in an array and when I will be need a specific day. I can count it for loops" will solve the problem. What I want to add is that it is not necessary to use loops. The shifts pattern repeats every 16 days – values for January 11th and January 27th are the same.
For a particular day d you can calculate the shift for each brigade considering the following pseudo-code:
D = The distance between a particular day d and January 1st in days.
A = Schedule for January 2019. A zero indexed array with 4 rows and 31 columns.
S1=A[1][D mod 16] will be the calculated shift number for brigade 1 at day d.
S2=A[2][D mod 16] will be the calculated shift number for brigade 2 at day d.
...
S4=A[4][D mod 16] will be the calculated shift number for brigade 4 at day d.
Knowing S1,S2,S3 and S4 is sufficient for getBrigadeNumber
to return the correct value.