×

Formatter.Duration (Duration Formatter)

The Duration Formatter is used to display time-based data.

Duration Formatter Constructor

Here is the constructor (function) of the Formater.Duration class:

Duration Formatter Instance Properties

Here are the properties of an instance of the Formatter.Duration class:

Duration Formatter Instance Methods (functions)

Here are the methods (functions) of an instance of the Formater.Duration class:

Total Hours as Duration


var dVal = Decimal.fromString(String(123.52)) var fmtr = new Formatter.Duration() fmtr.useVerboseFormat = true fmtr.stringFromDecimal(dVal) //--> "3 weeks 3.52 hours"
Total Hours of Duration


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

Calculations

The Decimal class has a set of functions for performing calculations with decimal instances, that can be used with to sum multiple durations:

Calculating Total of Multiple Durations


var durationA = "2w 3d 1.5h" var durationB = "3w 4d 6.25h" var durationC = "1w 3d 4.25h" var durations = [durationA, durationB, durationC] var fmtr = new Formatter.Duration() var totalTime = Decimal.zero durations.forEach(duration => { totalTime = totalTime.add( fmtr.decimalFromString(duration) ) }) fmtr.useVerboseFormat = true fmtr.stringFromDecimal(totalTime) //--> "8 weeks 1 day 4 hours"