> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automaticrostering.visma.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Periodic Rest

> Set targets for the minimum rest an employee should receive in each period

export const PeriodicRestMetricRows = () => <tr>
    <td><code className="whitespace-nowrap">PERIODIC_REST.CONTINUOUS_REST_VIOLATIONS</code></td>
    <td>Number of employee-rule combinations that violate the continuous-rest requirement.</td>
  </tr>;

The Periodic Rest rule can be used to set a minimum duration of continuous rest that an employee gets in a period. Of all the periods of rest the employee gets, the rule ensures that at least one of them is of the specified minimum duration per period.
A good example of this rule is to ensure that employees get at least 48 hours of continuous rest in each week, so that they will always have at least 2 consecutive days off, regardless of which days it is planned on.

<Card title="Rule schema">
  <ResponseField name="periodicRestRule" type="object">
    Used to set targets for continuous rest within specific periods.

    <Expandable title="properties">
      <ResponseField name="id" type="string" required>
        Unique identifier for the rule.
      </ResponseField>

      <ResponseField name="labels" type="array of string">
        Labels for the rule. Labels can be used to group rules together. For example, if multiple rules are related to the same shift type, they can all be labeled with the same label.
      </ResponseField>

      <ResponseField name="importance" type="string (enum: NONE | VERY_LOW | LOW | MEDIUM | HIGH | ...)" required>
        The importance of the rule. The higher the importance, the more it will be taking the rule into account. Under strict importance, the rule may never be violated.
      </ResponseField>

      <ResponseField name="filters" type="object">
        Filters to determine the scope of the rule. Used to indicate what the rule should be applied to (which employees, which shifts, etc). Leaving this empty means that the rule always applies.
      </ResponseField>

      <Expandable title="filters – properties">
        <ResponseField name="employees" type="object">
          Used to filter which employees the rule should be applied to. If not specified, the rule applies to all employees.
        </ResponseField>

        <Expandable title="employees – properties">
          <ResponseField name="ids" type="array of string">
            List of employee ids that the rule should be applied to.
          </ResponseField>

          <ResponseField name="labels" type="array of string">
            List of employee labels that the rule should be applied to.
          </ResponseField>

          <ResponseField name="matchTypes" type="object" />

          <Expandable title="matchTypes – properties">
            <ResponseField name="ids" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the id filters. For example, if set to NONE, entities with the specified ids will be excluded. Default: "ANY".
            </ResponseField>

            <ResponseField name="labels" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the label filters. For example, if set to ANY, entities that have any of the specified labels will be included. Default: "ANY".
            </ResponseField>
          </Expandable>
        </Expandable>

        <ResponseField name="shifts" type="object">
          Used to filter which shifts the rule should be applied to. If not specified, the rule applies to all shifts.
        </ResponseField>

        <Expandable title="shifts – properties">
          <ResponseField name="ids" type="array of string">
            List of shift ids that the rule should be applied to.
          </ResponseField>

          <ResponseField name="labels" type="array of string">
            List of shift labels that the rule should be applied to.
          </ResponseField>

          <ResponseField name="matchTypes" type="object" />

          <Expandable title="matchTypes – properties">
            <ResponseField name="ids" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the id filters. For example, if set to NONE, entities with the specified ids will be excluded. Default: "ANY".
            </ResponseField>

            <ResponseField name="labels" type="string (enum: NONE | ANY | ALL)">
              Used to indicate how to apply the label filters. For example, if set to ANY, entities that have any of the specified labels will be included. Default: "ANY".
            </ResponseField>
          </Expandable>
        </Expandable>
      </Expandable>

      <ResponseField name="targets" type="object" required>
        The target amounts of rest for each period.
      </ResponseField>

      <Expandable title="targets – properties">
        <ResponseField name="continuousRest" type="object">
          Target for a continuous amount of rest within each period.
        </ResponseField>

        <Expandable title="continuousRest – properties">
          <ResponseField name="minHours" type="number">
            The minimum number of hours of continuous rest each period should have.
          </ResponseField>
        </Expandable>
      </Expandable>

      <ResponseField name="options" type="object">
        Additional options for how the rule should be applied.
      </ResponseField>

      <Expandable title="options – properties">
        <ResponseField name="blockedPeriods" type="object">
          List of periods in the schedule. Periods can be defined explicitly or through a recurrent definition (for example, to generate weeks).
        </ResponseField>

        <Expandable title="blockedPeriods – properties">
          <ResponseField name="days" type="object">
            List of days in the schedule. Each day will become one period. By default, each period will last the entire day. If a startTime and/or endTime are specified, these will apply to each period.
          </ResponseField>

          <Expandable title="days – properties">
            <ResponseField name="dates" type="array of date (date)">
              List of dates in the schedule. Only allowed in CALENDAR payloads.
            </ResponseField>

            <ResponseField name="dayIndices" type="array of dayIndex">
              List of day indices in the schedule. Only allowed in RECURRING payloads.
            </ResponseField>

            <ResponseField name="daysOfWeek" type="array of dayOfWeek">
              List of days of the week. Will apply to all days in the schedule that match any of the specified weekdays.
            </ResponseField>

            <ResponseField name="startTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="endTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>
          </Expandable>

          <ResponseField name="customDefinitions" type="array of object">
            List of custom period definitions. Each custom period definition defines one period in the schedule.
          </ResponseField>

          <Expandable title="customDefinitions – item structure">
            <ResponseField name="startDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="startDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="endDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="endDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="startTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="endTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="applyTimeToAllDays" type="boolean">
              If true, the startTime and endTime will be applied to each individual day in the period. If false, the startTime will apply to the first day and the endTime will apply to the last day. Default: false.
            </ResponseField>
          </Expandable>

          <ResponseField name="recurrentDefinition" type="object">
            A recurrent definition to easily create a set of similar periods.
          </ResponseField>

          <Expandable title="recurrentDefinition – properties">
            <ResponseField name="daysPerPeriod" type="integer" required>
              The number of days in each period.
            </ResponseField>

            <ResponseField name="daysBetweenStarts" type="integer">
              The number of days between the start of each period. If not specified, this defaults to the value of daysPerPeriod, creating non-overlapping consecutive periods. Setting daysBetweenStarts to 1 will create a sliding window of periods.
            </ResponseField>

            <ResponseField name="startDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="startDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="endDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="endDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="startTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="endTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="applyTimeToAllDays" type="boolean">
              If true, the startTime and endTime will be applied to each individual day in the period. If false, the startTime will apply to the first day and the endTime will apply to the last day. Default: false.
            </ResponseField>
          </Expandable>

          <ResponseField name="labels" type="array of string">
            Provide labels to re-use periods that were defined in the configuration.
          </ResponseField>
        </Expandable>

        <ResponseField name="periodGroups" type="array of object">
          Groups of periods during which periodic rest should be met. The rule is considered satisfied if there is at least one period group for which the periodic rest is met for all of its periods. Cannot be used together with the regular 'periods' field.
        </ResponseField>

        <Expandable title="periodGroups – item structure">
          <ResponseField name="days" type="object">
            List of days in the schedule. Each day will become one period. By default, each period will last the entire day. If a startTime and/or endTime are specified, these will apply to each period.
          </ResponseField>

          <Expandable title="days – properties">
            <ResponseField name="dates" type="array of date (date)">
              List of dates in the schedule. Only allowed in CALENDAR payloads.
            </ResponseField>

            <ResponseField name="dayIndices" type="array of dayIndex">
              List of day indices in the schedule. Only allowed in RECURRING payloads.
            </ResponseField>

            <ResponseField name="daysOfWeek" type="array of dayOfWeek">
              List of days of the week. Will apply to all days in the schedule that match any of the specified weekdays.
            </ResponseField>

            <ResponseField name="startTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="endTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>
          </Expandable>

          <ResponseField name="customDefinitions" type="array of object">
            List of custom period definitions. Each custom period definition defines one period in the schedule.
          </ResponseField>

          <Expandable title="customDefinitions – item structure">
            <ResponseField name="startDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="startDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="endDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="endDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="startTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="endTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="applyTimeToAllDays" type="boolean">
              If true, the startTime and endTime will be applied to each individual day in the period. If false, the startTime will apply to the first day and the endTime will apply to the last day. Default: false.
            </ResponseField>
          </Expandable>

          <ResponseField name="recurrentDefinition" type="object">
            A recurrent definition to easily create a set of similar periods.
          </ResponseField>

          <Expandable title="recurrentDefinition – properties">
            <ResponseField name="daysPerPeriod" type="integer" required>
              The number of days in each period.
            </ResponseField>

            <ResponseField name="daysBetweenStarts" type="integer">
              The number of days between the start of each period. If not specified, this defaults to the value of daysPerPeriod, creating non-overlapping consecutive periods. Setting daysBetweenStarts to 1 will create a sliding window of periods.
            </ResponseField>

            <ResponseField name="startDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="startDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="endDay" type="object">
              Describes one day in the schedule.
            </ResponseField>

            <Expandable title="endDay – properties">
              <ResponseField name="date" type="string (date)">
                Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
              </ResponseField>

              <ResponseField name="dayIndex" type="integer">
                Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
              </ResponseField>
            </Expandable>

            <ResponseField name="startTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="endTime" type="string (time)">
              TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
            </ResponseField>

            <ResponseField name="applyTimeToAllDays" type="boolean">
              If true, the startTime and endTime will be applied to each individual day in the period. If false, the startTime will apply to the first day and the endTime will apply to the last day. Default: false.
            </ResponseField>
          </Expandable>

          <ResponseField name="labels" type="array of string">
            Provide labels to re-use periods that were defined in the configuration.
          </ResponseField>
        </Expandable>
      </Expandable>

      <ResponseField name="periods" type="object">
        List of periods in the schedule. Periods can be defined explicitly or through a recurrent definition (for example, to generate weeks).
      </ResponseField>

      <Expandable title="periods – properties">
        <ResponseField name="days" type="object">
          List of days in the schedule. Each day will become one period. By default, each period will last the entire day. If a startTime and/or endTime are specified, these will apply to each period.
        </ResponseField>

        <Expandable title="days – properties">
          <ResponseField name="dates" type="array of date (date)">
            List of dates in the schedule. Only allowed in CALENDAR payloads.
          </ResponseField>

          <ResponseField name="dayIndices" type="array of dayIndex">
            List of day indices in the schedule. Only allowed in RECURRING payloads.
          </ResponseField>

          <ResponseField name="daysOfWeek" type="array of dayOfWeek">
            List of days of the week. Will apply to all days in the schedule that match any of the specified weekdays.
          </ResponseField>

          <ResponseField name="startTime" type="string (time)">
            TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
          </ResponseField>

          <ResponseField name="endTime" type="string (time)">
            TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
          </ResponseField>
        </Expandable>

        <ResponseField name="customDefinitions" type="array of object">
          List of custom period definitions. Each custom period definition defines one period in the schedule.
        </ResponseField>

        <Expandable title="customDefinitions – item structure">
          <ResponseField name="startDay" type="object">
            Describes one day in the schedule.
          </ResponseField>

          <Expandable title="startDay – properties">
            <ResponseField name="date" type="string (date)">
              Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
            </ResponseField>

            <ResponseField name="dayIndex" type="integer">
              Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
            </ResponseField>
          </Expandable>

          <ResponseField name="endDay" type="object">
            Describes one day in the schedule.
          </ResponseField>

          <Expandable title="endDay – properties">
            <ResponseField name="date" type="string (date)">
              Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
            </ResponseField>

            <ResponseField name="dayIndex" type="integer">
              Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
            </ResponseField>
          </Expandable>

          <ResponseField name="startTime" type="string (time)">
            TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
          </ResponseField>

          <ResponseField name="endTime" type="string (time)">
            TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
          </ResponseField>

          <ResponseField name="applyTimeToAllDays" type="boolean">
            If true, the startTime and endTime will be applied to each individual day in the period. If false, the startTime will apply to the first day and the endTime will apply to the last day. Default: false.
          </ResponseField>
        </Expandable>

        <ResponseField name="recurrentDefinition" type="object">
          A recurrent definition to easily create a set of similar periods.
        </ResponseField>

        <Expandable title="recurrentDefinition – properties">
          <ResponseField name="daysPerPeriod" type="integer" required>
            The number of days in each period.
          </ResponseField>

          <ResponseField name="daysBetweenStarts" type="integer">
            The number of days between the start of each period. If not specified, this defaults to the value of daysPerPeriod, creating non-overlapping consecutive periods. Setting daysBetweenStarts to 1 will create a sliding window of periods.
          </ResponseField>

          <ResponseField name="startDay" type="object">
            Describes one day in the schedule.
          </ResponseField>

          <Expandable title="startDay – properties">
            <ResponseField name="date" type="string (date)">
              Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
            </ResponseField>

            <ResponseField name="dayIndex" type="integer">
              Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
            </ResponseField>
          </Expandable>

          <ResponseField name="endDay" type="object">
            Describes one day in the schedule.
          </ResponseField>

          <Expandable title="endDay – properties">
            <ResponseField name="date" type="string (date)">
              Date specified in ISO8601 format (YYYY-MM-DD). Only available in CALENDAR schedules.
            </ResponseField>

            <ResponseField name="dayIndex" type="integer">
              Day index relative to the horizon start day (starts at 0). Only available in RECURRING schedules.
            </ResponseField>
          </Expandable>

          <ResponseField name="startTime" type="string (time)">
            TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
          </ResponseField>

          <ResponseField name="endTime" type="string (time)">
            TIME ISO 8601 format hh:mm. Equivalent to the 24h format of a single day. Use 00:00 to represent midnight.
          </ResponseField>

          <ResponseField name="applyTimeToAllDays" type="boolean">
            If true, the startTime and endTime will be applied to each individual day in the period. If false, the startTime will apply to the first day and the endTime will apply to the last day. Default: false.
          </ResponseField>
        </Expandable>

        <ResponseField name="labels" type="array of string">
          Provide labels to re-use periods that were defined in the configuration.
        </ResponseField>
      </Expandable>
    </Expandable>
  </ResponseField>
</Card>

<Tip>
  The following example defines a periodic rest rule that ensures that all employees get at least one 48-hour long continuous rest in each week.

  ```json theme={null}
  {
    "rules": {
      "periodicRestRules": [
        {
          "id": "48-hours-per-week",
          "importance": "HIGH",
          "targets": {
            "continuousRest": {
              "minHours": 48
            }
          },
          "periods": {
            "recurrentDefinition": {
              "daysPerPeriod": 7
            }
          }
        }
      ]
    }
  }
  ```
</Tip>

<Tip>
  The following example defines a periodic rest rule that ensures that all employees get at least one 72-hour long continuous rest in each month.

  ```json theme={null}
  {
    "rules": {
      "periodicRestRules": [
        {
          "id": "72-hours-per-month",
          "importance": "HIGH",
          "targets": {
            "continuousRest": {
              "minHours": 72
            }
          },
          "periods": {
            "customDefinitions": [
              {
                "startDay": {
                  "date": "2022-01-01"
                },
                "endDay": {
                  "date": "2022-01-31"
                }
              },
              {
                "startDay": {
                  "date": "2022-02-01"
                },
                "endDay": {
                  "date": "2022-02-28"
                }
              }
            ]
          }
        }
      ]
    }
  }
  ```
</Tip>

## Metrics

The following [status metric](/v2/concepts/metrics) is available for tracking on Periodic Rest rules:

<table>
  <thead><tr><th>Metric key</th><th>Description</th></tr></thead>

  <tbody>
    <PeriodicRestMetricRows />
  </tbody>
</table>
