The relative duration table and the DurationCalculator methods The cmn_relative_duration table supports the definition of a due date as either a duration of time or a relative duration. This table consists of two fields: "name" and "script". The "script" field contains the relative duration calculation script. This script includes the "calculator" variable, which is used to calculate the due date. The DurationCalculator script include can be used to perform the duration calculations. The following are methods that are available in this script include. See the ServiceNow Developers site for API information. Table 1. DurationCalculator script include table Method Description setSchedule(String schedID, [String timezone]) Sets the schedule and time zone to be used for calculating the due date. setStartDateTime(GlideDateTime start) Sets the start time for the duration calculations. If 'start' is blank, uses current date/time. calcDuration(int seconds) Calculates the end date and time. Upon completion the this.endDateTime and this.seconds properties will be set to indicate the results of the calculation. calcRelativeDuration(String relativeDurationID) Calculates the duration using the specified relative duration script. Upon completion the this.endDateTime and this.seconds properties will be set to indicate the results of the calculation. getEndDateTime() Gets the this.endDateTime property that was set by calcDuration/calcRelativeDuration indicating the end date and time for the duration. 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.Note: 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 getTotalSeconds() Gets the this.totalSeconds property that was set by calcDuration/calcRelativeDuration indicating the total number of seconds between the start and end times of the duration. The following functions are used in relative duration scripts: Table 2. Relative duration script functions Function Description boolean isAfter(GlideDateTime dt, String time) Is 'time' of day after the time of day specified by 'dt'? dt, if blank, uses current date/time. time is in "hh:mm:ss" in 24-hour format. calcRelativeDueDate(GlideDateTime start, int days, String endTime) Calculates the due date starting at 'start' and adding 'days' using the schedule and time zone. When we find the day that the work is due on, set the time to 'endTime' of that day. Upon completion, this.endDateTime and this.seconds properties will be set to indicate the results of the calculation. If endTime is blank, use end of the ending work day.