v7.3.0
SupportExamplesFree Trial

Duration

An immutable-style value object representing a time duration. Each Duration has a numeric magnitude and a time unit (e.g. 'hour', 'day', 'week'). Durations can be constructed from explicit values, from a shorthand string like '2h' or '4d', or from a config object. They are used throughout the Scheduler and Gantt products for task durations, lag values, and calendar intervals. Use isEqual to compare durations regardless of their unit, and milliseconds to obtain a normalized value.

// From magnitude and unit
const d1 = new Duration(5, 'day');

// From shorthand string const d2 = new Duration('2h');

// From config object const d3 = new Duration({ magnitude : 30, unit : 'minute' });

// Static factory (returns null for null/undefined input) const d4 = Duration.from('1w');

// Compare durations d1.isEqual(new Duration(5, 'day')); // true

Supported units

"millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", "year"

Useful members

Member Description
magnitude The numeric magnitude of this duration
unit The time unit ('day', 'hour', etc.)
milliseconds Read-only total duration in milliseconds
isEqual(other) Returns true if two durations represent the same span of time
negate() Returns a negated copy
from(value) Static factory that converts strings, numbers, or objects to a Duration

See also

  • DateHelper - Date/time utility used for unit parsing and conversion
No results

Properties

Properties are getters/setters or publicly accessible variables on this class
    • Get/Set numeric magnitude value.

    • milliseconds : Number
      READONLY

      The milliseconds property is a read only property which returns the number of milliseconds in this Duration

    • Get/set duration unit to use with the current magnitude value. Valid values are:

      • "millisecond" - Milliseconds
      • "second" - Seconds
      • "minute" - Minutes
      • "hour" - Hours
      • "day" - Days
      • "week" - Weeks
      • "month" - Months
      • "quarter" - Quarters
      • "year"- Years

    Functions

    Functions are methods available for calling on the class

    Type definitions

    Source path

    Core/data/Duration.js

    Contents