GlideDuration - Scoped

The scoped GlideDuration class provides methods for working with spans of time or durations.

GlideDuration objects store the duration as a date and time from January 1, 1970, 00:00:00. As a result, setValue() and getValue() use the scoped GlideDateTime object for parameters and return values.

Scoped GlideDuration - add(GlideDuration duration)

Add the specified duration to the object.

Table 1. Parameters
Name Type Description
duration GlideDuration The value to add to the object.
Table 2. Returns
Type Description
GlideDuration The sum of the current and the added duration.
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.add(duration2);
gs.info(answer.getDisplayValue());

Output:

Scoped GlideDuration - getByFormat(String format)

Gets the duration in the specified format.

Table 3. Parameters
Name Type Description
format String The duration format.
Table 4. Returns
Type Description
String The current duration in the specified format.
var dur = new GlideDuration('3 22:00:00');
gs.info(dur.getByFormat('HH:mm'));

Output:

Scoped GlideDuration - getDayPart()

Gets the number of days.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
Number The number of days.
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getDayPart());

Output:

Scoped GlideDuration - getDisplayValue()

Gets the display value of the duration in number of days, hours, and minutes.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String The number of days, hours, and minutes.
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getDisplayValue());

Output:

Scoped GlideDuration - getDurationValue()

Gets the duration value in "d HH:mm:ss" format.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
String The duration value.
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getDurationValue());

Output:

Scoped GlideDuration - getRoundedDayPart()

Gets the rounded number of days. If the time part is more than 12 hours, the return value is rounded up. Otherwise, it is rounded down.

Table 11. Parameters
Name Type Description
none
Table 12. Returns
Type Description
Number The day part, rounded.
var dur = new GlideDuration('3 11:00:00');
gs.info(dur.getRoundedDayPart());

Output:

Scoped GlideDuration - getValue()

Gets the internal value of the GlideDuration object.

GlideDuration objects store the duration as a date and time from January 1, 1970, 00:00:00.

Table 13. Parameters
Name Type Description
none
Table 14. Returns
Type Description
String The duration in the object's internal format, which is the date and time from January 1, 1970, 00:00:00.
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getValue());
Output:
1970-01-04 12:00:00

Scoped GlideDuration - GlideDuration()

Instantiates a GlideDuration object.

Table 15. Parameters
Name Type Description
None

      

Output:

Scoped GlideDuration - GlideDuration(GlideDuration another)

Instantiates a GlideDuration object by cloning the value of another GlideDuration object.

Table 16. Parameters
Name Type Description
another GlideDuration Another scoped GlideDuration object.

      

Output:

Scoped GlideDuration - GlideDuration(Number milliseconds)

Instantiates a GlideDuration object with the specified duration.

Table 17. Parameters
Name Type Description
milliseconds Number The duration value in milliseconds.

      

Output:

Scoped GlideDuration - GlideDuration(String displayValue)

Instantiates a GlideDuration object with the specified display value.

Table 18. Parameters
Name Type Description
displayValue String The display value.

      

Output:

Scoped GlideDuration - setDisplayValue(String asDisplayed)

Sets the display value.

Table 19. Parameters
Name Type Description
asDisplayed String The duration in "d HH:mm:ss" format.
Table 20. Returns
Type Description
void
var dur = new GlideDuration(); 
dur.setDisplayValue('3 08:00:00');
gs.info(dur.getDisplayValue());

Output:

Scoped GlideDuration - setValue(Object o)

Sets the internal value of the GlideDuration object.

GlideDuration objects store the duration as a date and time from January 1, 1970, 00:00:00.

Table 21. Parameters
Name Type Description
o Object The duration in the object's internal format, which is the date and time from January 1, 1970, 00:00:00.
Table 22. Returns
Type Description
void
var dur = new GlideDuration();
dur.setValue('1970-01-05 08:00:00'); // sets internal DateTime value. The String will be parsed into a GlideDateTime object.
gs.info(dur.getDisplayValue());
Output:
4 Days 8 Hours

Scoped GlideDuration - subtract(GlideDuration duration)

Subtracts the specified duration from the current duration.

Table 23. Parameters
Name Type Description
duration GlideDuration The duration to subtract.
Table 24. Returns
Type Description
void
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.subtract(duration2);
gs.info(answer.getDisplayValue());
Output:
3 Days 9 Hours