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


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


fmtr = new Formatter.Duration() dVal = fmtr.decimalFromString("3w 3d 3h") 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


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