DurationCalculator - Global

Provides methods for calculating durations and due dates.

DurationCalculator - calcDuration(Number seconds)

Calculates an end date and time based on a specified start datetime and duration (seconds).

Upon completion, this.endDateTime, this.seconds, and this.totalSeconds properties are set to indicate the results of the calculation. Prior to calling this method, you must call setStartDateTime() with the start time to use in the computation.

Table 1. Parameters
Name Type Description
seconds Number Number of seconds to add to the startDateTime to compute the other values.
Table 2. Returns
TypeDescription
BooleanFalse if input value is not a number.

var gdt = new GlideDateTime("2012-05-01 00:00:00");
dc.setStartDateTime(gdt);
if(!dc.calcDuration(2*24*3600)){ // 2 days
  gs.log("*** Error calculating duration");
  return;
}

DurationCalculator - calcRelativeDueDate(GlideDateTime start, Number days, String endTime)

Calculates the due date starting at start and adding days using the schedule and time zone.

Called from relative duration definitions, initiated by calcRelativeDuration(), as calculator.calcRelativeDueDate(calculator.startDateTime, days). When the day that the work is due is found, sets the time to endTime of that day. If there are not enough days left in the schedule, uses the last day in the schedule.

Table 3. Parameters
Name Type Description
start GlideDateTime Start datetime for the computation.
days Number Number of days to add to the start datetime.
endTime String Time due of the computed day due in "hh:mm:ss" format, or blank to indicate the end of the work day
Table 4. Returns
TypeDescription
BooleanTrue if the completion date is within the schedule. False if the completion date falls outside the schedule. Undefined if no schedule was set prior to calling this method.
var dc = new DurationCalculator();
dc.calcRelativeDueDate("2012-04-10 08:00:00", 2, "08:00:00")

DurationCalculator - calcRelativeDuration(String relativeDurationID)

Calculates the duration using the specified relative duration script.

Upon completion, the this.endDateTime and this.seconds properties are set to indicate the results of the calculation.

Table 5. Parameters
Name Type Description
relativeDurationID String sys_id of relative duration schedule (table cmn_relative_duration).
Table 6. Returns
Type Description
Boolean The result of the duration script.

var dc = new DurationCalculator();
dc.calcRelativeDuration('08fcd0830a0a1b2600074f56b1ad7cb');

DurationCalculator - calcScheduleDuration(String startTime, String endTime)

Gets the actual duration between startTime and endTime within the already-specified schedule and optionally overridden timezone. Sets this.endDateTime (for completeness), this.seconds, and this.totalSeconds.

Sets this.endDateTime (for completeness), this.seconds, and this.totalSeconds.

Table 7. Parameters
Name Type Description
startTime String The start time. If not provided the current value is used (set using setStartDateTime()).
endTime String The end time. If not provided the current value is used (set using setEndDateTime()).
Table 8. Returns
TypeDescription
NumberThe schedule duration in seconds (same as calling getSeconds()). Returns 0 if endTime is before startTime.

var dc = new DurationCalculator();
gs.print(dc.calcScheduleDuration("2012-04-10 08:00:00","2012-04-14 06:00:00"));

*** Script: 338400

DurationCalculator - calcScheduleDuration(GlideDateTime startTime, GlideDateTime endTime)

Gets the actual duration between startTime and endTime within the already-specified schedule and optionally overridden timezone. Sets this.endDateTime (for completeness), this.seconds, and this.totalSeconds.

Sets this.endDateTime (for completeness), this.seconds, and this.totalSeconds.

Table 9. Parameters
Name Type Description
startTime GlideDateTime The start time. If not provided the current value is used (set using setStartDateTime()).
endTime GlideDateTime The end time. If not provided the current value is used (set using setEndDateTime()).
Table 10. Returns
TypeDescription
Number The schedule duration in seconds (same as calling getSeconds()). Returns 0 if endTime is before startTime.

DurationCalculator - DurationCalculator( )

Constructor for DurationCalculator class.

Table 11. Parameters
Name Type Description
None

var dc = new DurationCalculator();

DurationCalculator - getEndDateTime( )

Gets the endDateTime property that was set by calcDuration/calcRelativeDuration, indicating the end date and time for the duration.

Table 12. Parameters
Name Type Description
None
Table 13. Returns
TypeDescription
GlideDateTimeThe end datetime.
var dc =new DurationCalculator();
dc.calcDuration(52);
gs.print(dc.getEndDateTime());

2012-04-17 20:57:27

DurationCalculator - getSeconds( )

Gets the this.seconds property that was set by calcDuration/calcRelativeDuration, indicating the total number of seconds of work to be performed for the duration. This is the total work time, not the total time between start and end times and may be used to determine percentages of the work time.

This is the total work time, not the total time between start and end times and may be used to determine percentages of the work time.

Table 14. Parameters
Name Type Description
None
Table 15. Returns
TypeDescription
NumberThe total work time, in seconds.

var dc = new DurationCalculator();
dc.calcDuration(52);
gs.print(dc.getSeconds());

*** Script: 52

DurationCalculator - getTotalSeconds( )

Gets the totalSeconds value that was set by a call to calculate(record).

Table 16. Parameters
Name Type Description
None
Table 17. Returns
TypeDescription
NumberThe total number of seconds.

var dc = new DurationCalculator();
dc.calcDuration(52);
gs.print(dc.getTotalSeconds());

*** Script: 52

DurationCalculator - isAfter(GlideDateTime dt, String tm)

Checks if a time occurs after a specified time of day.

Table 18. Parameters
Name Type Description
dt GlideDateTime The Datetime to compare to.
tm String The test datetime.
Table 19. Returns
TypeDescription
BooleanTrue if tm is after dt.

var dc = new DurationCalculator();
gs.print(dc.isAfter("2012-04-10 08:00:00", "07:00:00"));

*** Script: true

DurationCalculator - setSchedule(String schedId, String timezone)

Sets the schedule and time zone to use for calculating the due date.

Table 20. Parameters
Name Type Description
schedId String The schedule sys_id (table cmn_schedule).
timezone String (Optional) Time zone string value.
Table 21. Returns
TypeDescription
void
var dc = new DurationCalculator(); 
dc.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae', 'Los Angeles');

DurationCalculator - setStartDateTime(String start)

Sets the start datetime for the duration calculations.

Table 22. Parameters
Name Type Description
start String (Optional) The start time in GMT for subsequent calculations. If not present then the current datetime is used.
Table 23. Returns
TypeDescription
void

var dc = new DurationCalculator();
dc.setStartDateTime("2012-04-10 08:00:00")

DurationCalculator - setStartDateTime(GlideDateTime description, Number amount)

Sets the start datetime for the duration calculations.

Table 24. Parameters
Name Type Description
description GlideDateTime (Optional) The start time in GMT for subsequent calculations. If not present then the current datetime is used.
amount Number amount
Table 25. Returns
TypeDescription
void

var dc = new DurationCalculator();
dc.calcDuration(52);
gs.print(dc.getEndDateTime());

DurationCalculator - setTimeZone(String timezone)

Sets the time zone to use for calculating the due date.

Table 26. Parameters
Name Type Description
timezone String Value of the time zone.
Table 27. Returns
TypeDescription
void

var dc = new DurationCalculator();
      dc.setTimeZone("Los Angeles");