# Shift Pattern not changing with Day Light saving

Go to solution Solved by John Brezovec,

## Recommended Posts

Hi all,

I am based in the UK and wanted to define shift pattern that changes with time zones.

I have created a condition for a 12 hour shifts that are on days for 2 consecutive days and then on nights for 2 consecutive nights. [Each shift will have 4 working days (2 days and 2 nights and 4 days off]

Consider 4 shifts in this shift pattern, namely: Shift 1, Shift 2, Shift 3, Shift 4. The shift starts at 8am and ends at 20:00. After which the next shift starts at 20:00 and ends at 8:00

I am using the following formula:

In the next step, I am defining my Night Shift using below formula:

And then I am defining my Days Shift using below formula:

After this, I combined, the days and night condition:

\$days.union(\$n)

Then I defined my first shift:

Shift A:

I then moved the next shift by 2 days, Shift B:

And then used this shift to define next one and so on, by moving each shift by 2 days from previous one.

The issue I am having is that the shift is not aligned with daylight saving.

##### Share on other sites

• Seeq Team

By default, functions like periods and shifts will use UTC time. There is an optional timeZone argument to these functions that will make them timezone/DST aware. An example from the documentation:

```periods(4year, 4year, '2021-01-20T12:00:00',
'America/New_York')```
##### Share on other sites

Hi John, thank you for the response.

Could you please help me with how can I use this in my example to get shifts aligned and updated with time zones?

##### Share on other sites

• Seeq Team
• Solution

Looking at this again, since your schedule is a little simpler than EOWeO, I'd create this condition a little differently.

I'd represent each shift as a union (AND) of several smaller periodic conditions. For example, the day shifts for Shift A in your company could be represented as times when all the following conditions are present:

• Day Shifts (08:00-20:00 every day)
• 4 Days On (A periodic condition 4 days long that occurs every 8 days)
• First 2 Days of the 4 Days On (Periodic condition 2 days long that occurs every 4 days)

Visually Shift A would look like:

•  the AND of all the conditions marked with 1
• the AND of all the conditions marked with 2

Then you can shift that condition by increments of 2 days to get the other three of your shifts. We can put this all into one formula that looks like:

```\$shift_identifier = 'A' // TODO: change this identifier
\$offset = 0d // TODO: Change offset for each shift

\$tz = 'Europe/London'

\$days = shifts(8, 12, \$tz)
\$nights = shifts(20, 12, \$tz)
\$on4 = periods(4d, 8d, toTime('2000-01-01T08:00:00Z') + \$offset, \$tz)
\$first2 = periods(2d, 4d, toTime('2000-01-01T08:00:00Z') + \$offset, \$tz)
\$second2 = periods(2d, 4d, toTime('2000-01-01T08:00:00Z') + 2d + \$offset, \$tz)

combineWith(
\$days and \$on4 and \$first2,
\$nights and \$on4 and \$second2
).setProperty('Shift', \$shift_identifier)```

You would copy this four times, one for each shift, adjusting the shift identifier as well as the offset. I'm adjusting the offset directly within the periods() function in order to keep everything DST aware rather than using the move() function, which can mess up when DST takes effect.

The final result of this looks like this:

##### Share on other sites

Hi John. This works like a charm. Thanks alot. 🙂

• 1