📜 ⬆️ ⬇️

Consider a shift schedule in the mind



Many people who have a shift schedule. The problem with such a schedule is the difficulty to quickly calculate for any date what day it is: work or holiday. There are many online services for calculating shift schedules, but it is even easier to do this in mind. This article will discuss the algorithm of calculation in the mind for any shift schedule.

As in the article “Calculation of the day of the week in the mind,” the algorithm will be based on the month offsets.

The article will be considered work schedule 3/3. Those. “Week” in our case will last 6 days:

Рабочий день 1 Рабочий день 2 Рабочий день 3 Выходной день 1 Выходной день 2 Выходной день 3 

The most important thing is not to make a mistake when calculating the offset for the first month of the year. All subsequent months will depend on it.

For example, let the first working day of the year be January 2, i.e. January 2, 3 and 4 are working days; 5, 6, 7, respectively, are days off.

In my case it was like this
December 31 - Workday 1
January 3 - Workday 2
January 4 - Workday 3
Therefore, to simplify the calculations, let us assume that January 2, 3, and 4 are working days.
This is important for calculating the offset for January.

From the above, we get a calendar for January:



where green cells are working days, red ones are days off.

The number of days in a row is equal to the number of days in our “week”, in our example it is 6.

January 1 - Day 3;
January 2 - Business Day 1 (the beginning of the "week").

Before the first day of the month there are 5 empty yellow cells, which means that the shift for January in our case will be equal to 5.

Continuing, we get the calendar for February (non-leap year):



As you can see, the offset for February is 0, since the month starts on the first working day.

Next for March:



The offset for March is 4, and for April - 5, since April 1 falls on the 6th day of the week, and there will be 5 empty squares in front of it.

Next, we count to the month we need.

In my case, the offsets for the first 6 months will be:
5, 0, 4, 5, 5, 5 - January, February, March, April, May and June. Remember 6 numbers is not difficult.

To calculate whether this is a working day or a weekend, you need to add the offset of the month to the date and find the remainder of the division by the duration of the "week":

$$ display $$ Balance = (date + offset \; month) \% (duration \; "week") $$ display $$

Depending on the balance, we determine the day:

1, 2 and 3 - working days
4, 5 and 0 - days off

For example, for February 23: 23 (date) + 0 (shift of February) = 23. The balance of 23% 6 = 5, this is the second holiday.

For March 8: 8 (date) + 4 (shift for March) = 12. 12% 6 = 0. This means that March 8 is the last day off, March 9 to work.

Another example to fix:

April 22 + 5 (offset for April) = 27, the remainder of the division by 6 is 3 - the last working day.

The disadvantage of the algorithm is a violation of the schedule after the holidays: the table of displacements must be recalculated or taken vacation in such a way that the schedule is not violated. For example, if you take a vacation after 3 working days for “the number of working days in a row” * “an odd number” of days (3, 9, 15, 21 days of vacation), then the schedule discussed in the article will not be disturbed.

Using this algorithm, you can calculate any day in your mind for a few seconds, no calendars and online services.

Source: https://habr.com/ru/post/440270/