×

Duration

In terms of OmniPlan projects, a duration is a specified amount of time. The time represented by an instance of the Duration class is organized as either “project time” or “elapsed (contiguous) time.”

The length of time required to complete OmniPlan projects is expressed in standard time increments, such as days, weeks, months, and years. And it is common for the time it takes to complete a task, to span multiple “work-days” which are comprised of a specified number of “work-hours” per overall day.

However, some tasks, such as pouring and setting concrete, by nature require that their process be done in one pass, no matter how many contiguous hours that may require. This measure of time is called “elapsed-time” which is a single contiguous amount of time.

To visualize the relationship between the two duration formats (work-time & elapsed-time), imagine you’ve mixed up a pint of Jello®! You can pour the mixture into either three small cups, or into one larger cup. The smaller cups may take up more space on the counter but they contain the same amount of Jello as the larger cup — it’s the packaging that is different.

jello-combo

This same relationship applies to how time is displayed in OmniPlan. A duration is a value that can be measured via the project schedule components or via elapsed time. The default is via project schedule, but scripts can create durations of either type when necessary.

Instance Properties

The properties of a duration instance. These can be used to retrieve the time values of duration objects in the desired format.

Class Functions

Functions for creating instances of the Duration class. Use these functions to create instances of the Duration class in the desired format.

Examples

Create a Duration using Hours


var duration = Duration.workHours(15) duration.workSeconds //--> 54000
Create a Duration using Days


var duration = Duration.elapsedDays(5) duration.elapsedDays //--> 5

Work-Time Example

Assigning a duration of 12 work-hours to a new task:

omniplan://localhost/omnijs-run?script=try%7Btask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0Atask%2Etitle%20%3D%20%22Task%20taking%2012%20work%2Dhours%22%0Atask%2Eduration%20%3D%20Duration%2EworkHours%2812%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Project Task with Work-Time Duration
 

var task = actual.rootTask.addSubtask() task.title = "Task taking 12 work-hours" task.duration = Duration.workHours(12)
new-task-with-duration

Note that the task occurs over a two-day period, with the first section of time being the 8-hours of the first day, and the second section of time consisting of the remaining four hours.

Elapsed-Time (Contiguous-Time) Example

Creating a project task with a contiguous-time duration of 26½ hours:

omniplan://localhost/omnijs-run?script=try%7Bduration%20%3D%20Duration%2EelapsedHourMinSec%2826%2C30%2C0%29%0Atask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0Atask%2Etitle%20%3D%20%22Paint%20Room%20including%20Drying%20Time%22%20%0Atask%2Eduration%20%3D%20duration%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Project Task with Contiguous-Time Duration
 

var task = actual.rootTask.addSubtask() task.title = "Paint Room including Drying Time" task.duration = Duration.elapsedHourMinSec(26, 30, 0)
contiguous-time-task

As with the previous example, this task occurs over a two-day period, but consists of a single contiguous block of time, which is not segmented to fit into the default “work-day” format of 8-hours per day.

Duration Formatter

There is a Formatter.Duration class that is shared (link) by all Omni applications that can be used when calculating and displaying duration values.

Total Hours of Duration


var fmtr = new Formatter.Duration() var dVal = fmtr.decimalFromString("3w 3d 3h") var totalHours = Number(dVal.toString()) //--> 147