DurationCalculator calcScheduleDuration Mystery

stevejarman
Giga Guru

I'm having some problems using a DurationCalculator, which seems to be related to the schedule itself. Hoping someone has some thoughts on it.

I've included some snippets from the source code below, as well as screenshots of the schedule.

The summary version of the issue:

  • NOT USING the schedule, calcScheduleDuration calculates the duration between 2018-03-02 10:55:19 and 2018-03-12 15:22:40 as 10 04:27:21
  • USING the schedule, calcScheduleDuration calculates the duration between 2018-03-02 10:55:19 and 2018-03-12 15:22:40 as 3 00:00:00

I seem to consistently lose my remainder, and get a rounded number of days only... or something like that.

var dc = new DurationCalculator();

var bhSchedule = new GlideRecord("cmn_schedule");
bhSchedule.addQuery("name", "General Business Hours 7am - 7pm");
bhSchedule.query();

if (bhSchedule.next()) {
  dc.setSchedule(bhSchedule.getUniqueValue());
}

//
// A BUNCH OF OTHER STUFF HAPPENS IN HERE
//

gs.log("STEVEJ17 :: " + outages[x].start.toString() + " --> " + outages[x].end.toString());
// OUTPUT IS STEVEJ17 :: 2018-03-02 10:55:19 --> 2018-03-12 15:22:40

var focusDurationMs = dc.calcScheduleDuration(outages[x].start.toString(), outages[x].end.toString()) * 1000;
var focusDuration = new GlideDuration(focusDurationMs);

gs.log("STEVEJ17 :: " + focusDuration.getDurationValue());
// OUTPUT IS STEVEJ17 :: 3 00:00:00


// IF I COMMENT OUT THE SCHEDULE - I.E. THIS SECTION:
/*
var bhSchedule = new GlideRecord("cmn_schedule");
bhSchedule.addQuery("name", "General Business Hours 7am - 7pm");
bhSchedule.query();

if (bhSchedule.next()) {
  dc.setSchedule(bhSchedule.getUniqueValue());
}
*/

// THEN RESULTS LOOK CORRECT
// OUTPUT IS STEVEJ17 :: 2018-03-02 10:55:19 --> 2018-03-12 15:22:40
// OUTPUT IS STEVEJ17 :: 10 04:27:21

find_real_file.png

 

find_real_file.png

5 REPLIES 5

stevejarman
Giga Guru

Does anyone have any thoughts on this? Does anyone know from experience that the Duration Calculator actually works?

ARG645
Tera Guru

I created a schedule exactly like yours. and I ran a Fix script and It worked fine for me. The only difference between my code and your code is , I hard-coded the Dates in calcScheduleDuration function.

var dc = new DurationCalculator();

var bhSchedule = new GlideRecord("cmn_schedule");
bhSchedule.addQuery("name", "General Business Hours 7am - 7pm");
bhSchedule.query();

if (bhSchedule.next()) {
  dc.setSchedule(bhSchedule.getUniqueValue()); 
}

var focusDurationMs = dc.calcScheduleDuration("2018-03-02 10:55:19", "2018-03-12 15:22:40") * 1000;
var focusDuration = new GlideDuration(focusDurationMs);

gs.log("STEVEJ17 :: " + focusDuration.getDurationValue());
// OUTPUT IS STEVEJ17 :: 3 01:22:40

Can you log what exactly are the values of : outages[x].start.toString(); and outages[x].end.toString()

 

Hey - thanks for that! Very interesting...

You can see in my code the output from those strings. They *should* be fine.

At least you've given me some hope that it's not far off working. There must just be something strange going on...

gs.log("STEVEJ17 :: " + outages[x].start.toString() + " --> " + outages[x].end.toString());
// OUTPUT IS STEVEJ17 :: 2018-03-02 10:55:19 --> 2018-03-12 15:22:40

Definitely seems like in my case it's dropping the time portion of what's being passed to calcScheduleDuration and only keeping the date part.

Perfect example:

STEVEJ :: 1 :: 2018-03-20 08:58:39 :: 2018-03-21 09:42:08 :: 43200000 :: 12:00:00

That's start, end, milliseconds, duration

It's basically giving me 7am - 7pm which makes no sense.