Audrey H. Acclaimed Contributor.
Acclaimed Contributor.
631 views

How to check if a date is/was within service hours

Hi,

I'm trying to do some conditional calculations based on whether a date is/was within service hours or not and I'm wondering if anyone knows a way to check a datetime against a duty calendar with a holiday calendar associated with it to indicate that it is either in servicehours or outside of service hours.

For example, I am opening (or have opened)  an IM and if I opened it during service hours I need the interval for a subsequent expression to be '18:00:00' but if I opened it outside of business hours then I need the interval to be '09:00:00'.  This secondary expression could trigger on open of a new ticket or on update of an existing ticket, so I need to be able to check the datetime against the calduty and holiday table to see if the open.time is/was within service hours.  Does anyone know of a way to do this?

Audrey

0 Likes
4 Replies
Absent Member.. John Stagaman Absent Member..
Absent Member..

Re: How to check if a date is/was within service hours

I had to do this several years ago and the best option I came up with was to initialize a variable for comparison, then use the RAD function to get the interval based on business hours for the two times. If it was non-zero, the ticket was in business hours. 

It was something like:

Set $testTime to open.time in $file plus 5 seconds.

Run the RAD app to determine the interval between open.time and $testTime based on the current business calendar. If the returned interval was non-zero then the 5 second period fell within the business calendar. It's not perfect, but it was close enough for that requirements (I don't recall, this was a long time ago).

----------------------------------------------------
Kudos - what, where, how, and why
Want Good Answers? Ask Good Questions...
Acclaimed Contributor.. Kelalek2 Acclaimed Contributor..
Acclaimed Contributor..

Re: How to check if a date is/was within service hours

Like John, also I had to do a solution, that is close to your requirement. In our case, I was asked to do a "lightweight" SLA check if (or what part of) the outage time was within the promised service hours.

I found from this board a following JavaScript, that uses a RAD application to do a dirty work. Like John proposed, you could input following parameters for a code and use a returned duration as a sign whether the open time was within the service hours.

  • start - open.time
  • end - open.time + some seconds
  • calend - the name of your dutytable
// Source: http://h30499.www3.hp.com/t5/HP-Service-Manager-Service/SLO-duration-type-Calculation-End-of-the-month/m-p/4787115#M54171

function CalcInterval(start, end, calend) {

var rteReturnValue = new SCDatum();
var Names = new SCDatum();
var Vals = new SCDatum();
var rec = new SCFile("probsummary");

Names.setType(8);//type array
Vals.setType(8);//type array

Names.push("file");
Names.push("name");
Names.push("times,1");
Names.push("times,2");
Names.push("prompt");

Vals.push(rec);
Vals.push("time.spent"); //any Date/time field
Vals.push(start);
Vals.push(end);
Vals.push(calend);

var rc = system.functions.rtecall("callrad",
rteReturnValue,
"calendar.calc.interval.fc", //RAD app name
Names,
Vals,
false);

return rec.time_spent;

}

The RAD app recognizes holidays etc. out-of-office hours, if a dutytable includes a reference to a holiday calendar.

I hope this helps!

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
Audrey H. Acclaimed Contributor.
Acclaimed Contributor.

Re: How to check if a date is/was within service hours

Thanks John and Kelalek2,

While looking for a more simple solution, I had a similar thought as both of you for my workaround, but I used the calendar.calc.date.fc and fed it my caldutyhours record and an interval of '00:00:01'.  Then if the resulting date value is more than 1 second past my starting value I consider it to have been opened outside of business hours.  Also, since I have additional date calculations to perform based on the results, I actually used SM scripts, so I do this in the first script and then based on the results I move to different scripts etc.  It does work, but I consider it a messy solution and had been hoping for something a bit cleaner.  I opened a ticket with HP, but they tell me they don't currently have any RAD app or script to easily do what I want. It does seems like they might be considering developing something.

Thanks very much to both of you for your suggestions.

Audrey

0 Likes
Outstanding Contributor.. exeptt Outstanding Contributor..
Outstanding Contributor..

Re: How to check if a date is/was within service hours

@Audrey H. 

If I do not mistaken, you can use next function.

Note: holidays not included

function checkDate(dat){
  var file = new SCFile('caldutyhours',SCFILE_READONLY);
  file.doSelect("name=\"day shift\"");//your working calendar name goes here  
  var fDay = dat.getDay()+1;
  var fTime = dat.toLocaleTimeString();
  var trimTime = function (arg) {return eval(eval('arg+fDay')).toUTCString().substring(18,26)}
    if (fTime>trimTime('file.begin_hour_') && fTime<trimTime('file.begin_hour_')  && fTime>trimTime('file.break_start_') && fTime>trimTime(file.break_end_)) return true;
    else return false; 
}

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.