Schedule.js


A flexible scheduler for tasks, work items, reservations, meetings, etc.

The easiest way to schedule work items with complex dependencies across developers that all have different work schedules. Or reserve elevators in an apartment building. Or schedule the company ping pong tournament. Works in Node and in the browser.

View on GitHub Get Started

Basic usage

  // Define a set of tasks
  var tasks = [
    {id: 1, duration: 60, available: later.parse.text('every weekday')},
    {id: 2, duration: 30, dependsOn: [1], resources: ['A']},
    {id: 3, duration: 30, dependsOn: [1], resources: [['A','B']]}
  ];

  // Define a set of resources
  var resources = [
    {id: A},
    {id: B, available: later.parse.text('after 10:00am and before 6:00pm')}
  ];

  // Create the schedule for all of the tasks
  schedule.create(tasks, resources);
See a more complete, fully documented example of scheduling work items or reservations.

Minimal library dependencies

Schedule only depends on Later, a small library for working with recurring schedules. With no other dependencies using Schedule is easy.

Serializable

Tasks, resources, and resulting schedules are simple json objects that are fully serializable. Easy to store in databases and in caches.

Flexible

Tasks and resources support Later schedules to define when a task can be scheduled or a resource can be reserved.

Unit tests included

Supported by a test suite of over 70 unit and scenario tests, additional tests for new scenarios always welcome.

Deterministic

All schedules are completely deterministic, meaning that they always produce the same set of results regardless of when you calculate them.

Quick start

Step 1: Install

Schedule is available through both npm and bower. After installing, Schedule is available in the schedule namespace.

Using npm and Node.js:

  $ npm install schedulejs
  var schedule = require('schedulejs');

Using bower and a browser:

  $ bower install later
  $ bower install schedule
  <script src="later.min.js" type="text/javascript"></script>
  <script src="schedule.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    // schedule namespace is available
  </script>
More information on building, running tests, and running benchmarks.

Step 2: Define your tasks

Tasks are the things that you want to schedule. You need to specify at least an id and a duration in minutes. You can then customize how the tasks get scheduled by:

  • Specifying dependencies between tasks
  • Adding a Later schedule that determines when the task is available
  • Including one or more resources that the task requires (supports AND and OR semantics)
  • Providing a priority that determines task order after dependencies have been met
  • Indicating whether or not the task can be split up into multiple time blocks
  var tasks = [
    {id: 1, duration: 60},
    {id: 2, duration: 60, available: later.parse.text('every weekday')},
    {id: 3, duration: 30, dependsOn: [1], priority: 100},
    {id: 4, duration: 30, dependsOn: [1], minLength: 30},
    {id: 5, duration: 90, dependsOn: [2,3]},
    {id: 6, duration: 45, dependsOn: [4], resources: ['A']},
    {id: 7, duration: 60, dependsOn: [5], resources: ['A', 'B']},
    {id: 8, duration: 30, dependsOn: [6,7], resources: [['A', 'B'], 'C']}
  ];
More information on tasks, task options and the task generator.

Step 3: Define your resources

Resources are the things that your tasks require in order to be completed. By default, resources are automatically reserved when they are used by a task. Customize how the resources are used by:

  • Adding a Later schedule that determines when the resources are available
  • Specifying if resources need to be reserved or can be used by multiple tasks
  var resources = [
    {id: A},
    {id: B, available: later.parse.text('after 10:00am and before 6:00pm')},
    {id: C, isNotReservable: true}
  ];
More information on resources, resource options and the resource generator.

Step 4: Define your project availability and start date

Create a Later schedule for the overall project, no tasks will be scheduled outside of this schedule. Then decide when you want to start scheduling tasks from.

  var projectAvailability = later.parse.text('every weekday'),
      startDate = new Date();

Step 5: Create the schedule

Finally pass your tasks, resources, project availability and start date to create. The return value is the schedule with start and end times for each task that was successfully scheduled.

  schedule.create(tasks, resources, projectAvailability, startDate);
More information on creating schedules and understanding the results.


View full documentation