Managing Task Durations

Tasks take time: they have a duration. Realistic task duration help give a realistic project end date. Aspose.Tasks allows developers set task duration in projects.

Working with Durations

The Duration and DurationFormat properties exposed by the Task class are used to determine the planned duration and format of the duration of a task:

Duration in Microsoft Project

To see a task’s duration in Microsoft Project one can select More Views and then Task Entry From the View menu.

Setting task duration in Microsoft Project

how to manage task duration in Microsoft Project

Setting task duration using Aspose.Tasks

The following examples increases and decreases the task duration to 1 week and half week respectively.

 1// Create a new project and add a new task
 2Project project = new Project();
 3Task task = project.getRootTask().getChildren().add("Task");
 4
 5// Task duration in days (default time unit)
 6Duration duration = task.get(Tsk.DURATION);
 7System.out.println("Duration equals 1 day:" + duration.toString().equals("1 day"));
 8
 9// Convert to hours time unit
10duration = duration.convert(TimeUnitType.Hour);
11System.out.println("Duration equals 8 hrs: "+ duration.toString().equals("8 hrs"));
12
13// Increase task duration to 1 week and display if duration is updated successfully
14task.set(Tsk.DURATION, project.getDuration(1, TimeUnitType.Week));
15System.out.println("Duration equals 1 wk: " + task.get(Tsk.DURATION).toString().equals("1 wk"));
16
17// Decrease task duration and display if duration is updated successfully
18task.set(Tsk.DURATION, task.get(Tsk.DURATION).subtract(0.5));
19System.out.println("Duration equals 0.5 wks: " + task.get(Tsk.DURATION).toString().equals("0.5 wks"));
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.