API Update - repeating weeks

Alejandro
Alejandro
  • Updated

 

If you do not rely on the user's schedules property for any tools implemented using our API then you do not need to make any changes.

  

If you do rely on the user's schedules property then the following describes the upcoming changes to user schedules:

Our current schedule system allows for admins to set weekly schedules for their users with a starting date, a list of working/non-working days, and working shift times. The current format is as follows.

 

Week days mapping:

0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday

[
   // schedule 1
   {
       start: 'yyyy-MM-dd',
       days: {
           0: {
               active: Boolean,
               shifts: [
                   { start: 'hh:mm', end: 'hh:mm' },
                   {...},
                   ...
               ]
           },
           1: { active: Boolean, shifts: [...] },
           2: { active: Boolean, shifts: [...] },
           3: { active: Boolean, shifts: [...] },
           4: { active: Boolean, shifts: [...] },
           5: { active: Boolean, shifts: [...] },
           6: { active: Boolean, shifts: [...] }
       }
   },
   // schedule 2
   {...},
   // schedule n
   ...
]

While this works for most users, we now have many who use alternating or repeating schedules and to provide better flexibility we have decided to allow for setting up multi-week schedules.

The new format is largely the same with the only difference being the 'days' property on a schedule being an array.

The following example above shows a user who gets every second Friday off but this is not limited to just 2 weeks:

[
   // schedule 1
   {
       start: 'yyyy-MM-dd',
       days: [
           // week 1
           {
               0: { active: false, shifts: [...] },
               1: { active: true,  shifts: [...] },
               2: { active: true,  shifts: [...] },
               3: { active: true,  shifts: [...] },
               4: { active: true,  shifts: [...] },
               5: { active: true,  shifts: [...] },
               6: { active: false, shifts: [...] }
           },
           // week 2
           {
               0: { active: false, shifts: [...] },
               1: { active: true,  shifts: [...] },
               2: { active: true,  shifts: [...] },
               3: { active: true,  shifts: [...] },
               4: { active: true,  shifts: [...] },
               5: { active: false, shifts: [...] },
               6: { active: false, shifts: [...] }
           },
           // week n
           ...
       ]
   },
   // schedule 2
   {...},
   // schedule n
   ...
]

This allows a user to set up multiple weeks that will repeat indefinitely from the start instead of requiring the user to set up 52 schedules just to cover a single year.

Our suggested route of action would be to map the new format back into the old format for a chosen period which can then be passed to your existing tools without requiring any other modifications to be made.

Once the new system is released, all existing user schedules will be automatically updated to return the days object as an array with the existing week as the only object.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.