Docs
  • Solver
  • Models
    • Field Service Routing
    • Employee Shift Scheduling
  • Platform
Try models
  • Employee Shift Scheduling
  • Employee resource constraints
  • Work limits
  • Weekend minutes worked per period

Employee Shift Scheduling

    • Introduction
    • Planning AI concepts
    • Metrics and optimization goals
    • Getting started with employee shift scheduling
    • Understanding the API
    • Employee shift scheduling user guide
    • Employee resource constraints
      • Employee availability
      • Employee contracts
      • Work limits
        • 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
        • 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
      • Shift rotations and patterns
        • Shift rotations and patterns
        • Shift rotations
        • Single day shift sequence patterns
        • Multi-day shift sequence patterns
        • Daily shift pairings
        • Overlapping shifts
        • Shift start times differences
        • Minutes between shifts
      • Shift type diversity
        • Shift type diversity
        • Shift types worked per period
        • Unique tags per period
      • Fairness
        • Fairness
        • Balance time worked
        • Balance shift count
      • Pairing employees
      • Shift travel and locations
    • Shift service constraints
      • Alternative shifts
      • Cost management
      • Demand-based scheduling
      • Mandatory and optional shifts
      • Shift assignments
      • Skills and risk factors
    • Recommendations
    • Real-time planning
    • Time zones and Daylight Saving Time (DST)
    • Changelog
    • Upgrading to the latest versions
    • Feature requests

Weekend minutes worked per period

There are different techniques for managing employees' working hours.

For different scenarios see Work limits.

This guide shows you how to manage employees' hours with weekend minutes worked per period. This puts a limit on how often employees work on weekends, for instance, if employees should only work 960 minutes (or 16 hours) on weekends throughout a period of one month.

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

Prerequisites

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.

1. Define weekend minutes worked per period

Period rules are defined in contracts:

{
  "contracts": [
    {
      "id": "fullTimeContract",
      "periodRules": [
        {
          "id": "Max16WeekendHoursPerMonth",
          "period": "MONTH",
          "weekendsLimit":
          {
            "weekendMinutesWorkedMax": 960
          },
          "satisfiability": "REQUIRED"
        }
      ]
    }
  ]
}

Period rules can define how many weekend minutes employees work in a given period, for instance, 960 minutes (16 hours) 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 weekendMinutesWorkedMax with the maximum number of weekend minutes worked per period.

periodRules can include or exclude shifts based on shift tags.

{
  "contracts": [
    {
      "id": "fullTimeContract",
      "periodRules": [
        {
          "id": "Max16WeekendHoursPerMonth",
          "period": "MONTH",
          "includeShiftTags": ["Part-time"],
          "shiftTagMatches": "ALL",
          "weekendsLimit":
          {
            "weekendMinutesWorkedMax": 960
          },
          "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 weekend minutes worked per period

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

Shifts will be left unassigned if assigning them would break the Weekend minutes 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 960 weekend minutes (16 hours) per month.

Only the weekend shifts are shown in the example.

2 shifts, totaling 960 minutes, are assigned and 6 shifts are left unassigned to avoid breaking the Weekend minutes worked per period not in required range for employee hard constraint.

required 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": "Required weekend minutes worked per period example"
    }
  },
  "modelInput": {
    "contracts": [
      {
        "id": "fullTimeContract",
        "periodRules": [
          {
            "id": "Max16WeekendHoursPerMonth",
            "period": "MONTH",
            "weekendsLimit":
            {
              "weekendMinutesWorkedMax": 960
            },
            "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>
{
  "run": {
    "id": "ID",
    "name": "Required weekend minutes worked per period example",
    "submitDateTime": "2025-06-13T03:39:41.064047335Z",
    "startDateTime": "2025-06-13T03:39:52.644606223Z",
    "activeDateTime": "2025-06-13T03:39:52.781562453Z",
    "completeDateTime": "2025-06-13T03:40:23.517839171Z",
    "shutdownDateTime": "2025-06-13T03:40:23.792089752Z",
    "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
  }
}

modelOutput contains the schedule with 2 shifts (960 minutes) assigned and 6 shifts unassigned.

inputMetrics provides a breakdown of the inputs in the input dataset.

KPIs provides the KPIs for the output including:

{
    "assignedShifts": 2,
    "unassignedShifts": 6,
    "activatedEmployees": 1,
    "assignedMandatoryShifts": 2
}

3. Preferred weekend minutes worked per period

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

{
  "contracts": [
    {
      "id": "fullTimeContract",
      "periodRules": [
        {
          "id": "Max16WeekendHoursPerMonth",
          "period": "MONTH",
          "weekendsLimit":
          {
            "weekendMinutesWorkedMax": 960
          },
          "satisfiability": "PREFERRED"
        }
      ]
    }
  ]
}

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

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 960 weekend minutes (16 hours) per month.

All 8 shifts are assigned, totaling 3,840 minutes, and a soft penalty is applied to the score run.

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 weekend minutes worked per period example"
    }
  },
  "modelInput": {
    "contracts": [
      {
        "id": "fullTimeContract",
        "periodRules": [
          {
            "id": "Max16WeekendHoursPerMonth",
            "period": "MONTH",
            "weekendsLimit":
            {
              "weekendMinutesWorkedMax": 960
            },
            "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>
{
  "run": {
    "id": "ID",
    "name": "Preferred weekend minutes worked per period example",
    "submitDateTime": "2025-06-13T04:48:31.932443806Z",
    "startDateTime": "2025-06-13T04:48:43.866658502Z",
    "activeDateTime": "2025-06-13T04:48:44.064214043Z",
    "completeDateTime": "2025-06-13T04:49:14.991589132Z",
    "shutdownDateTime": "2025-06-13T04:49:15.256369159Z",
    "solverStatus": "SOLVING_COMPLETED",
    "score": "0hard/0medium/-5760soft",
    "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
  }
}

modelOutput contains the schedule with all 8 shifts assigned to Ann.

inputMetrics provides a breakdown of the inputs in the input dataset.

KPIs provides the KPIs for the output including:

{
    "assignedShifts": 8,
    "activatedEmployees": 1,
    "assignedMandatoryShifts": 8
}

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.

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