Creating a new schedule from a set of tasks and resources.
Once your tasks and resources have been defined, they can be used to generate a new schedule. The schedule includes the start and end times for each task that was successfully scheduled and a list of any tasks that could not be scheduled. The schedule also contains a lot of additional details such as the resources that were reserved and the causes of any delays in the schedule.
Tip All schedules are timezone agnostic. When you need to calculate occurrences, you can decide to perform the calculation using local time or UTC.
// set later to use UTC time (the default) schedule.date.UTC(); // set later to use local time schedule.date.localTime();
Once the tasks and resources have been defined, creating a new schedule
is done using schedule.create
.
Generates a new schedule for each of the tasks
, reserving
resources
as required. The schedules generated will always
occur at valid times according to the Later
schedule
specified and will start no earlier than start
.
// 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, later.parse.text('every weekday'), new Date());
Creating a new schedule produces a JSON object with a lot of details pertaining to the schedule that was created. Here we'll take a quick look at the results from the work item example.
The schedule object is returned from schedule.create
and contains summary information about the schedule. The set of tasks
that was successfully scheduled is returned as a map in
scheduledTasks
(described fully below). Any tasks that
could not be scheduled are listed in the failedTasks
array. If there were no failures, success
will be true. The
start
time is the earliest time that any task was scheduled to start and
end
is the latest finishing time of any task.
Note All
dates are returned as milliseconds from the Unix epoch, you can convert them
to dates using new Date(val);
.
{ scheduledTasks: {...see below...} failedTasks: null, success: true, start: 1364050800000, end: 1364157000000 }
The scheduledTasks
is a map that contains one entry for
each task that was successfully scheduled. The key is the task
id
. The value is an object containing an array of
schedule items (described fully below), the total duration
of the task, and a summary of the schedule.
The summary includes
the first time the task is scheduled for (earlyStart
),
the time the task is scheduled to finish (earlyFinish
),
and the earliest time that a dependent task requires this task to be
complete (lateFinish
).
The float
is the difference between
the lateFinish
and the earlyFinish
in
minutes. Any tasks that has a float of 0 are in the critical path which means
any slip in the completion of this task will cause the schedule end date
to slip as well.
{ 'Purchase supplies': { schedule: [...see below...], duration: 120, earlyStart: 1364058000000, earlyFinish: 1364065200000, lateFinish: 1364067000000, floatAmt: 30 }, ... }
The task schedule
is an array of times that the task
has been scheduled for. It is returned as an array since a task
can be broken up into multiple segments to better fit the schedule.
Each segment includes the set of resources
that was
reserved, the start
and end
times of the segment, the duration
of the segment, and a list of
delays
which are fully described below.
[ { resources: [ 'Bob', 'Sara' ], start: 1364058000000, end: 1364065200000, duration: 120, success: true, delays: {...see below...} }, ... ]
The delays
list is a list of the things that caused
a task segment to not start as soon as all of its dependencies were
met. In this example, the task itself was not available, nor were
Bob or Sara (all due to the available scheduled defined for them).
{ '_taskPurchase supplies': { needed: 1363849200000, available: 1363878000000 }, Bob: { needed: 1363849200000, available: 1364058000000 }, Sara: { needed: 1363849200000, available: 1364050800000 } }