
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2018 03:03 AM
Been asked to get the business duration of a ticket from opened until closed/now. Simple I say, we'll just have a quick durationCalculator, and throw a schedule/timezone, and the start/end dates at it.
var dc = new DurationCalculator();
dc.setSchedule('2c59445b4fdb9b8042800b318110c756');
var dur = dc.calcScheduleDuration(start, end);
var durSec = dc.getSeconds();
var durTotalSec = dc.getTotalSeconds();
if start/end are sufficiently far apart, dur and durSec cap out at MAX_INT_VAL/1000 (presumably behind the scenes the seconds value is being stored in millisecs), however durTotalSec seems to give a valid response. I'm just running this across multiple tickets in a non-prod to validate, but can't seem to find any good documentation on getTotalSeconds, other than totalSeconds being set during calcScheduleDuration and it being a standard getter.
Anyone able to shed any light?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2018 08:13 AM
Hi Douglas,
After reading your question, I was playing around with DurationCalculator() script include. After examining the script include and after running some background scripts. Below is what i found the main difference between getSeconds and getTotalSeconds.
Summary:-
getTotalSeconds: Doesn't care about the schedule, it will give the difference in seconds between startDate and EndDate without taking schedule into consideration
getSeconds: Gives the Difference in Seconds, it will take the schedule into consideration(only if a schedule is set)
Example: -
Say I have a schedule that is 24/5 Weekdays only.
var start = "2018-08-23 08:00:00"; // Tomorrow, Thursday
var end = "2018-08-28 08:00:00";// next week Tuesday
var dc = new DurationCalculator();
dc.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae');// My 24/5 Schedule
var dur = dc.calcScheduleDuration(start, end);
var durSec = dc.getSeconds();// Skips weekdays as it involves the schedule into calculation
var durTotalSec = dc.getTotalSeconds();//Doesnt skip weekdays as it excludes the schedule in calculation
gs.print(durSec/86400);
gs.print(durTotalSec/86400);
Output:
*** Script: 3
*** Script: 5
Other things I found which may help you understand:
getTotalSeconds is calculated from below logic
_totalSeconds: function(/* GlideDateTime */ startTime, /* GlideDateTime */ endTime) {
return Math.max(0, (Math.floor(endTime.getNumericValue()/1000) - Math.floor(startTime.getNumericValue()/1000) ));
},
Some Useful comments
/**
* Get 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)
*/
getSeconds: function() {
return this.seconds;
},
/**
* Get 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.
*/
getTotalSeconds: function() {
return this.totalSeconds;
},
Please mark my my answer Correct/Helpful if applicable, so that it will help others in future.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2018 01:36 AM
Thanks Aman - I was working on the script until the night I went on Vacation - but you are correct, I've marked your response as correct to the original question.