Professional Documents
Culture Documents
DurationCalculator API
DurationCalculator API
DurationCalculator - Global
The DurationCalculator API provides methods for calculating durations
and due dates.
Calculates an end date and time based on current start date and time
and passed in duration (seconds).
Parameters
Number of seconds to
add to the start date
and time to compute
seconds Number
the end date and
time, seconds, and
total seconds values.
Returns
Type Description
Example
if(!dc.calcDuration(2*24*3600)){ // 2 days
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Output
Calculates the due date starting at the passed in start time and adding
the number of days using the current schedule and time zone.
Parameters
GlideDateTime object
that contains the
start GlideDateTime
start date for the
computation.
Number of days to
days Number
add to the start date.
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Format: HH:mm:ss
Returns
Type Description
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
dc.calcDuration(3*24*3600); // 3 days
dc.calcRelativeDueDate(startTime, "3", "07:00:00");
DurationCalculator -
calcRelativeDuration(String relativeDurationID)
Parameters
sys_id of relative
duration schedule
relativeDurationID String (table
cmn_relative_duration
).
Returns
Type Description
Example
Returns the duration between the startTime and the endTime within the
already-specified schedule and optionally overridden timezone.
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Parameters
Optional. Display
value for the end time.
Optional. Display
value for the start time.
Returns
Type Description
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Output
DurationCalculator - calcScheduleDuration(GlideDateTime
startTime, GlideDateTime endTime)
Returns the duration between the startTime and the endTime within the
already-specified schedule and optionally overridden timezone.
Parameters
Optional.
GlideDateTime object
that contains the start
time to use.
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Optional.
GlideDateTime object
that contains the end
time to use.
endTime GlideDateTime
Default: Uses the
current date and
time (set using
setEndDateTime()).
Returns
Type Description
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Output
DurationCalculator - DurationCalculator( )
Parameters
None
Example
DurationCalculator - getEndDateTime( )
Parameters
None
Returns
Type Description
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Example
2012-04-17 20:57:27
DurationCalculator - getSeconds( )
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.
Parameters
None
Returns
Type Description
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Output
DurationCalculator - getTotalSeconds( )
Parameters
None
Returns
Type Description
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Output
Parameters
Either a GlideDateTime
object or a display
value date and time
to compare to the
GlideDateTime or passed in tm value.
dt
String If you pass a display
value date and time,
the method converts
it to a GlideDateTime
object.
Format: HH:mm:ss
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Returns
Type Description
Example
Sets the schedule and time zone to use for calculating the due date.
Parameters
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Returns
Type Description
void
Example
Output
Sets the start date and time for the duration calculations.
Parameters
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Returns
Type Description
void
Example
Sets the start date and time for the duration calculations.
Parameters
GlideDateTime object
that contains the
description GlideDateTime start time in
GMT for subsequent
calculations.
Returns
Type Description
void
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference
Sets the time zone to use for calculating the due date.
Parameters
Returns
Type Description
void
Example
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.