HOW TO FIND COMPLETE OVERLAP FOR BLACKOUT SCHEDULES

surya h
Tera Contributor

 

var plannedStart = '2023-06-01 20:00:00';
var plannedEnd = '2023-06-10 20:00:00';

var newstart = new GlideDateTime(plannedStart);
var newend = new GlideDateTime(plannedEnd);

var blackoutSchedule = new GlideRecord('cmn_schedule_span');
blackoutSchedule.addQuery('schedule', 'a445656545654kjhkjhjhgjhghg8');
blackoutSchedule.query();

var isPartialOverlap = false;
var isCompleteOverlap = false;

while (blackoutSchedule.next()) {
var recurrence = blackoutSchedule.schedule;
var schedule = new GlideSchedule(recurrence);

if (schedule.isInSchedule(newstart) && schedule.isInSchedule(newend)) {
isCompleteOverlap = true;
break;
} else if (schedule.isInSchedule(newstart) || schedule.isInSchedule(newend)) {
isPartialOverlap = true;
}
}

if (isCompleteOverlap) {
gs.info("Complete overlap with the schedule");
} else if (isPartialOverlap) {
gs.info("Partial overlap with the schedule");
} else {
gs.info("No overlap with the schedule");
}

 



For partial overlap it is working as expected, but for complete overlap it is not working, it shows that the planned start and planned end are not in schedules window

for example: 

PARTIAL OVERLAP:

plannedStart = '2023-05-30 20:00:00';
plannedEnd = '2023-06-03 20:00:00';

 

is working when my schedule entry start from 2023-06-02 20:00:00 to 2023-06-04 20:00:00

plannedStart = '2023-06-03 20:00:00';
plannedEnd = '2023-06-10 20:00:00';

 

is working when my schedule entry start from 2023-06-02 20:00:00 to 2023-06-04 20:00:00



COMPLETE OVERLAP:

plannedStart = '2023-06-01 20:00:00';
plannedEnd = '2023-06-10 20:00:00';

 

is not working when even my schedule entry start from 2023-06-02 20:00:00 to 2023-06-04 20:00:00


kindly provide me a work around for this.


Thanks in advance.

5 REPLIES 5

surya h
Tera Contributor

I found a other workaround for this but facing other issues
all dates on (DD/MM/Y) format

I have created a monthly Blackout schedule from '2023-06-10 10:00:00' and ends on '2023-06-20 20:00:01'
As you all know this will be recurring every month on the same dates.

Now i have my change request planned start and planned end dates

var plannedStart = '2023-08-01 10:00:00';
var plannedEnd = '2023-08-10 20:00:01';

so this should show me the popup that it is present in Blackout schedule(EXISTING IN THE BELOW SCRIPT)

NOW I NEED HELP ON GETTING A POPUP WITH THE CONFLICT START AND END DATE as below:
It is already in Blackout schedule from '2023-08-10 10:00:00' and ends on '2023-08-20 20:00:01' as my planned start is in 8th month and planned end is in 8th month

as of now i can able to populate only the display dates in the schedule. but i need to populate for the future dates and months in the popup

 

var plannedStart = '2023-08-01 10:00:00';
var plannedEnd = '2023-08-10 20:00:01';

var blackoutSchedule = new GlideRecord('cmn_schedule_span');
blackoutSchedule.addQuery('schedule', 'klkjhjkhfd787878');
blackoutSchedule.query();

while (blackoutSchedule.next()) {
  var recurrencerule = blackoutSchedule.schedule;
  var schedule = new GlideSchedule(recurrencerule);

  var gdt_start = new GlideDateTime(plannedStart);
  var gdt_end = new GlideDateTime(plannedEnd);

  var dur = schedule.duration(gdt_start, gdt_end);
  var schedule_time = dur.getNumericValue() / 1000;

  gs.info(schedule_time);

  if (schedule.isInSchedule(gdt_start) || schedule.isInSchedule(gdt_end) || schedule_time > 0) {
    gs.info("this is already present in blackout as it overlaps the schedule start and schedule end dates");
    break;
  } else {
    gs.info('not an overlap');
  }
}

 

NOW I NEED HELP ON GETTING A POPUP WITH THE CONFLICT START AND END DATE
kindly help me out with the solution how to get conflicted start date and end date of the schedule