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.
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.
elapsed (Boolean r/o) • A boolean value that indicates whether or not this duration is measured in project time or elapsed calendar time.
elapsedDays (Number r/o) • Number of days, for a duration measured in elapsed time.
elapsedHours (Number r/o) • Number of hours, for a duration measured in elapsed time.
elapsedMinutes (Number r/o) • Number of minutes, for a duration measured in elapsed time.
elapsedMonths (Number r/o) • Number of months, for a duration measured in elapsed time.
elapsedSeconds (Number r/o) • Number of seconds, for a duration measured in elapsed time.
elapsedWeeks (Number r/o) • Number of weeks, for a duration measured in elapsed time.
elapsedYears (Number r/o) • Number of years, for a duration measured in elapsed time.
workSeconds (Number r/o) • Number of project schedule work-seconds of duration, for a duration measured in project time.
Class Functions
Functions for creating instances of the Duration class. Use these functions to create instances of the Duration class in the desired format.
workSeconds(seconds:Number) → (Duration) • Create a duration instance for the passed-in number of seconds using project schedule time.
workHours(hours:Number) → (Duration) • Create a duration instance for the passed-in number of hours using project schedule time.
elapsedHourMinSec(hours:Number, minutes:Number, seconds:Number) → (Duration) • Create a duration instance for the passed-in number of hours, minutes, and seconds.
elapsedDays(days:Number) → (Duration) • Create a duration instance for the passed-in number of days.
elapsedYearMonthDay(years:Number, months:Number, days:Number) → (Duration) • Create a duration instance for the passed-in year, month, and day.
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:
Project Task with Work-Time Duration
var task = actual.rootTask.addSubtask()
task.title = "Task taking 12 work-hours"
task.duration = Duration.workHours(12)
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:
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)
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