Docs
  • Solver
  • Models
    • Field Service Routing
    • Employee Shift Scheduling
    • Pick-up and Delivery Routing
  • Platform
Try models
  • Employee Shift Scheduling
  • Employee resource constraints
  • Work limits
  • Weekends worked per period
  • latest
    • latest
    • 1.16.x

Employee Shift Scheduling

    • Introduction
    • Getting started: Hello world
    • User guide
      • Terms
      • Use case guide
      • Planning AI concepts
      • Constraints
      • Understanding the API
      • Demo datasets
      • Planning window
      • Time zones and Daylight Saving Time (DST)
      • Tags and tag types
      • Input validation
      • Metrics and optimization goals
      • Score analysis
    • Employee resource constraints
      • Employee contracts
      • Employee availability
      • Pairing employees
      • Shift travel and locations
      • Employee activation
      • Work limits
        • Minutes worked per period
        • Minutes worked in a rolling window
        • Minutes logged per period
        • Days worked per period
        • Days worked in a rolling window
        • Consecutive days worked
        • Shifts worked per period
        • Shifts worked in a rolling window
        • Weekend minutes worked per period
        • Weekends worked per period
        • Weekends worked in a rolling window
        • Consecutive weekends worked
      • Time off
        • Days off per period
        • Consecutive days off per period
        • Consecutive days off in a rolling window
        • Consecutive minutes off in a rolling window
        • Shifts to avoid close to day off requests
        • Consecutive weekends off per period
      • Shift rotations and patterns
        • Shift rotations
        • Single day shift sequence patterns
        • Minimize gaps between shifts
        • Multi-day shift sequence patterns
        • Daily shift pairings
        • Overlapping shifts
        • Shift start times differences
        • Minutes between shifts
      • Shift type diversity
        • Shift types worked per period
        • Unique tags per period
      • Fairness
        • Balance time worked
        • Balance shift count
    • Shift service constraints
      • Alternative shifts
      • Cost management
      • Demand-based scheduling
      • Mandatory and optional shifts
      • Shift assignments
      • Skills and risk factors
    • Manual intervention
    • Recommendations
    • Real-time planning
    • Real-time planning (preview)
    • Scenarios
      • Configuring labor law compliance
    • Changelog
    • Upgrade to the latest version
    • Feature requests

Weekends worked per period

There are different techniques for managing employees' working hours.

For different scenarios see Work limits.

Weekends worked per period rules limit how many weekends employees can work in a period, for instance, if employees should only work 1 weekend throughout a period of 1 month.

Period rules for weekends can be defined for a month or the entire schedule.

This guide explains managing employees' hours with weekends worked per period:

  • 1. Define weekends worked per period
  • 2. Required weekends worked per period
  • 3. Preferred weekends worked per period
  • 4. Managing overtime

1. Define weekends worked per period

Learn how to configure an API Key to run the examples in this guide:
  1. Log in to Timefold Platform: app.timefold.ai

  2. From the Dashboard, click your tenant, and from the drop-down menu select Tenant Settings, then choose API Keys.

  3. Create a new API key or use an existing one. Ensure the list of models for the API key contains the Employee Shift Scheduling model.

In the examples, replace <API_KEY> with the API Key you just copied.

Period rules are defined in contracts:

{
  "contracts": [
    {
      "id": "fullTimeContract",
      "periodRules": [
        {
          "id": "Max1WeekendPerMonth",
          "period": "MONTH",
          "weekendsLimit":
          {
            "weekendsWorkedMax": 1
          },
          "satisfiability": "REQUIRED"
        }
      ]
    }
  ]
}

Period rules can define how many weekends employees work in a given period, for instance, 1 weekend per month.

PeriodRules must include an ID.

period sets the period the rule applies to, for instance, DAY, WEEK, MONTH, SCHEDULE.

Further information about period:

DAY spans a single day and occurs every day in the schedule.

WEEK spans 7 days and occurs every week (including partial weeks) in the schedule. The default start of the week is Monday, but this can be overridden to any day in the week:

{
  "scheduleParameterization": {
    "weekStart": "THURSDAY"
  }
}

MONTH spans the entire month. MONTH has a variable number of days depending on the days in the month and occurs every month (including partial months) in the schedule.

SCHEDULE spans the entire schedule.

You can define custom periods to apply to this rule in the following way:
{
  "scheduleParameterization": {
    "periods": [
      {
        "id": "PAY_PERIOD",
        "dateSpans": [
          {
            "start": "2023-01-01",
            "end": "2023-01-15"
          }
        ]
      }
    ]
  }
}

The start and end dates are inclusive.

weekendsLimit rules can only be defined for periods MONTH or SCHEDULE.
Learn about counting days in period rules:

By default, period rules count shifts within the defined period if the shift starts within the defined period. For instance, if you define a rule that an employee can only work 1 shift a day, a night shift that started on the previous day but ends the following morning will not be counted and another shift might be assigned on the same day as the night shift ended.

To change this behavior change the field periodShiftOverlapKind from START_ONLY to START_AND_END.

{
  "periodRules": [
    {
      "id": "Max8HoursPerDayFullTime",
      "period": "DAY",
      "minutesWorkedMax": 480,
      "satisfiability": "REQUIRED",
      "periodShiftOverlapKind": "START_AND_END"
    }
}

The weekendsLimit object must include weekendsWorkedMax with the maximum number of weekend worked per period.

periodRules can include or exclude shifts based on shift tags.

{
  "contracts": [
    {
      "id": "fullTimeContract",
      "periodRules": [
        {
          "id": "Max1WeekendPerMonth",
          "period": "MONTH",
          "includeShiftTags": ["Part-time"],
          "shiftTagMatches": "ALL",
          "weekendsLimit":
          {
            "weekendsWorkedMax": 1
          },
          "satisfiability": "REQUIRED"
        }
      ]
    }
  ]
}
Further information about including or excluding shifts with shift tags:

Shifts with specific tags can be included or excluded by the rule. Tags are defined in shifts:

{
  "shifts": [
    {
      "id": "2027-02-01",
      "start": "2027-02-01T09:00:00Z",
      "end": "2027-02-01T17:00:00Z",
      "tags": ["Part-time"]
    }
  ]
}

Use includeShiftTags to include shifts with specific tags or excludeShiftTags to exclude shifts with specific tags.

shiftTagMatches can be set to ALL or ANY. The default behavior for shiftTagMatches is ALL, and if omitted, the default ALL will be used.

The rule can define either includeShiftTags or excludeShiftTags, but not both.

{
  "includeShiftTags": ["Part-time", "Weekend"],
  "shiftTagMatches": "ALL"
}

With shiftTagMatches set to ALL, all tags defined by the rule’s includeShiftTags attribute must be present in the shift. With shiftTagMatches set to ANY, at least one tag defined by the rule’s includeShiftTags attribute must be present in the shift.

{
  "excludeShiftTags": ["Part-time", "Weekend"],
  "shiftTagMatches": "ALL"
}

With shiftTagMatches set to ALL, all tags defined by the rule’s excludeShiftTags attribute cannot be present in the shift. This is useful when you want to exclude things in combination with each other. For instance, excluding the shift tags Part-time and Weekend with shiftTagMatches set to All, will exclude shifts that include the tags Part-time and Weekend from the rule. Shifts tagged only Part-time or only Weekend will not be excluded.

With shiftTagMatches set to ANY, any of the tags defined by the rule’s excludeShiftTags attribute cannot be present in the shift. This is useful when you need to exclude tags regardless of their relationship to other tags. For instance, excluding the shift tags Part-time and Weekend with shiftTagMatches set to ANY, will exclude any shift that includes the tags Part-time or Weekend, whether they occur together or not.

Each employee must specify which contracts apply to them:

{
  "employees": [
    {
      "id": "Ann",
      "contracts": [
        "fullTimeContract"
      ]
    }
  ]
}

The satisfiability can be REQUIRED or PREFERRED. If omitted, REQUIRED is the default.

2. Required weekends worked per period

When the satisfiability of the rule is REQUIRED, the Weekends worked per period not in required range for employee hard constraint is invoked, which makes sure the number of weekends worked per period does not exceed the limit specified in weekendsWorkedMax.

Shifts will be left unassigned if assigning them would break the Weekends worked per period not in required range for employee constraint.

In the following example, there are 8 shifts, 1 employee, and a rule with a required satisfiability that specifies the employee can work at most 1 weekend per month.

Only the weekend shifts are shown in the example.

2 shifts on 1 weekend are assigned and 6 shifts are left unassigned to avoid breaking the Weekends worked per period not in required range for employee hard constraint.

required weekends per period
  • Input

  • Output

Try this example in Timefold Platform by saving this JSON into a file called sample.json and make the following API call:
curl -X POST -H "Content-type: application/json" -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules [email protected]
{
  "config": {
    "run": {
      "name": "Required weekends worked per period example"
    }
  },
  "modelInput": {
    "contracts": [
      {
        "id": "fullTimeContract",
        "periodRules": [
          {
            "id": "Max1WeekendPerMonth",
            "period": "MONTH",
            "weekendsLimit":
            {
              "weekendsWorkedMax": 1
            },
            "satisfiability": "REQUIRED"
          }
        ]
      }
    ],
    "employees": [
      {
        "id": "Ann",
        "contracts": [
          "fullTimeContract"
        ]
      }
    ],
    "shifts": [
      {
        "id": "Sat 6",
        "start": "2027-02-06T09:00:00Z",
        "end": "2027-02-06T17:00:00Z"
      },
      {
        "id": "Sun 7",
        "start": "2027-02-07T09:00:00Z",
        "end": "2027-02-07T17:00:00Z"
      },
      {
        "id": "Sat 13",
        "start": "2027-02-13T09:00:00Z",
        "end": "2027-02-13T17:00:00Z"
      },
      {
        "id": "Sun 14",
        "start": "2027-02-14T09:00:00Z",
        "end": "2027-02-14T17:00:00Z"
      },
      {
        "id": "Sat 20",
        "start": "2027-02-20T09:00:00Z",
        "end": "2027-02-20T17:00:00Z"
      },
      {
        "id": "Sun 21",
        "start": "2027-02-21T09:00:00Z",
        "end": "2027-02-21T17:00:00Z"
      },
      {
        "id": "Sat 27",
        "start": "2027-02-27T09:00:00Z",
        "end": "2027-02-27T17:00:00Z"
      },
      {
        "id": "Sun 28",
        "start": "2027-02-28T09:00:00Z",
        "end": "2027-02-28T17:00:00Z"
      }
    ]
  }
}
To request the solution, locate the 'ID' from the response to the post operation and append it to the following API call:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules/<ID>
{
  "metadata": {
    "id": "ID",
    "name": "Required weekends worked per period example",
    "submitDateTime": "2025-06-13T05:45:08.168062776Z",
    "startDateTime": "2025-06-13T05:45:26.111472225Z",
    "activeDateTime": "2025-06-13T05:45:26.258624032Z",
    "completeDateTime": "2025-06-13T05:45:57.168793571Z",
    "shutdownDateTime": "2025-06-13T05:45:57.405050134Z",
    "solverStatus": "SOLVING_COMPLETED",
    "score": "0hard/-6medium/0soft",
    "tags": [
      "system.profile:default"
    ],
    "validationResult": {
      "summary": "OK"
    }
  },
  "modelOutput": {
    "shifts": [
      {
        "id": "Sat 6",
        "employee": "Ann"
      },
      {
        "id": "Sun 7",
        "employee": "Ann"
      },
      {
        "id": "Sat 13"
      },
      {
        "id": "Sun 14"
      },
      {
        "id": "Sat 20"
      },
      {
        "id": "Sun 21"
      },
      {
        "id": "Sat 27"
      },
      {
        "id": "Sun 28"
      }
    ]
  },
  "inputMetrics": {
    "employees": 1,
    "shifts": 8,
    "pinnedShifts": 0
  },
  "kpis": {
    "assignedShifts": 2,
    "unassignedShifts": 6,
    "disruptionPercentage": 0.0,
    "activatedEmployees": 1,
    "assignedMandatoryShifts": 2,
    "assignedOptionalShifts": 0,
    "travelDistance": 0
  }
}

3. Preferred weekends worked per period

When the satisfiability of the rule is PREFERRED, the Weekends worked per period not in preferred range for employee soft constraint is invoked.

{
  "contracts": [
    {
      "id": "fullTimeContract",
      "periodRules": [
        {
          "id": "Max1WeekendPerMonth",
          "period": "MONTH",
          "weekendsLimit":
          {
            "weekendsWorkedMax": 1
          },
          "satisfiability": "PREFERRED"
        }
      ]
    }
  ]
}

Shifts will be assigned to employees even if the shifts take the employee’s weekends worked over the limit specified by weekendsWorkedMax, however, this constraint adds a soft penalty to the dataset score for any matches to the constraint, incentivizing Timefold to find an alternative solution.

Every soft constraint has a weight that can be configured to change the relative importance of the constraint compared to other constraints.

Learn about constraint weights.

This rule is more likely to be satisfied for employees with a higher employee priority.

In the following example, there are 8 shifts, 1 employee, and a rule with a preferred satisfiability that specifies the employee should work at most 1 weekend per month.

All 8 shifts are assigned, and a soft penalty is applied to the dataset score.

preferred weekend minutes per period
  • Input

  • Output

Try this example in Timefold Platform by saving this JSON into a file called sample.json and make the following API call:
curl -X POST -H "Content-type: application/json" -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules [email protected]
{
  "config": {
    "run": {
      "name": "Preferred weekends worked per period example"
    }
  },
  "modelInput": {
    "contracts": [
      {
        "id": "fullTimeContract",
        "periodRules": [
          {
            "id": "Max1WeekendPerMonth",
            "period": "MONTH",
            "weekendsLimit":
            {
              "weekendsWorkedMax": 1
            },
            "satisfiability": "PREFERRED"
          }
        ]
      }
    ],
    "employees": [
      {
        "id": "Ann",
        "contracts": [
          "fullTimeContract"
        ]
      }
    ],
    "shifts": [
      {
        "id": "Sat 6",
        "start": "2027-02-06T09:00:00Z",
        "end": "2027-02-06T17:00:00Z"
      },
      {
        "id": "Sun 7",
        "start": "2027-02-07T09:00:00Z",
        "end": "2027-02-07T17:00:00Z"
      },
      {
        "id": "Sat 13",
        "start": "2027-02-13T09:00:00Z",
        "end": "2027-02-13T17:00:00Z"
      },
      {
        "id": "Sun 14",
        "start": "2027-02-14T09:00:00Z",
        "end": "2027-02-14T17:00:00Z"
      },
      {
        "id": "Sat 20",
        "start": "2027-02-20T09:00:00Z",
        "end": "2027-02-20T17:00:00Z"
      },
      {
        "id": "Sun 21",
        "start": "2027-02-21T09:00:00Z",
        "end": "2027-02-21T17:00:00Z"
      },
      {
        "id": "Sat 27",
        "start": "2027-02-27T09:00:00Z",
        "end": "2027-02-27T17:00:00Z"
      },
      {
        "id": "Sun 28",
        "start": "2027-02-28T09:00:00Z",
        "end": "2027-02-28T17:00:00Z"
      }
    ]
  }
}
To request the solution, locate the 'ID' from the response to the post operation and append it to the following API call:
curl -X GET -H 'X-API-KEY: <API_KEY>' https://app.timefold.ai/api/models/employee-scheduling/v1/schedules/<ID>
{
  "metadata": {
    "id": "ID",
    "name": "Preferred weekends worked per period example",
    "submitDateTime": "2025-06-13T06:02:11.439168397Z",
    "startDateTime": "2025-06-13T06:02:29.693348694Z",
    "activeDateTime": "2025-06-13T06:02:29.876484365Z",
    "completeDateTime": "2025-06-13T06:03:00.924300437Z",
    "shutdownDateTime": "2025-06-13T06:03:01.193540069Z",
    "solverStatus": "SOLVING_COMPLETED",
    "score": "0hard/0medium/-2880soft",
    "tags": [
      "system.profile:default"
    ],
    "validationResult": {
      "summary": "OK"
    }
  },
  "modelOutput": {
    "shifts": [
      {
        "id": "Sat 6",
        "employee": "Ann"
      },
      {
        "id": "Sun 7",
        "employee": "Ann"
      },
      {
        "id": "Sat 13",
        "employee": "Ann"
      },
      {
        "id": "Sun 14",
        "employee": "Ann"
      },
      {
        "id": "Sat 20",
        "employee": "Ann"
      },
      {
        "id": "Sun 21",
        "employee": "Ann"
      },
      {
        "id": "Sat 27",
        "employee": "Ann"
      },
      {
        "id": "Sun 28",
        "employee": "Ann"
      }
    ]
  },
  "inputMetrics": {
    "employees": 1,
    "shifts": 8,
    "pinnedShifts": 0
  },
  "kpis": {
    "assignedShifts": 8,
    "unassignedShifts": 0,
    "disruptionPercentage": 0.0,
    "activatedEmployees": 1,
    "assignedMandatoryShifts": 8,
    "assignedOptionalShifts": 0,
    "travelDistance": 0
  }
}

4. Managing overtime

Rules with a satisfiability of REQUIRED put a hard limit on how much work employees can be assigned (minutes, hours, days, shifts), and does not assign overtime.

A rule with a satisfiability of REQUIRED that states an employee can work a maximum of 1 weekends per period, will never assign the employee more than 1 weekends per period, even if assigning overtime would be beneficial to the overall schedule.

To allow for the possibility of overtime, use rules with a satisfiability of PREFERRED.

Set a rule with a PREFERRED satisfiability for the maximum number of weekends per period. Now, a rule with a satisfiability of PREFERRED that states an employee can preferably work a maximum of 1 weekends per period will allow the employee to be assigned more weekends per period (overtime) than specified by the rule when it is necessary to do so.

To place a limit on the total amount of overtime employees can be assigned, include both:

  • A rule with PREFERRED satisfiability for the maximum number of weekends per period that is equivalent to the employees normal weekends per period.

  • A rule with REQUIRED satisfiability for the maximum number of weekends per period (regular hours plus overtime).

The difference between the PREFERRED maximum weekends per period and REQUIRED maximum weekends per period is the total amount of overtime that can be assigned to employees.

Next

  • See the full API spec or try the online API.

  • Learn more about employee shift scheduling from our YouTube playlist.

  • See other options for managing employees' work hours: Work limits.

  • © 2026 Timefold BV
  • Timefold.ai
  • Documentation
  • Changelog
  • Send feedback
  • Privacy
  • Legal
    • Light mode
    • Dark mode
    • System default