Skip to content

Commit 9709c14

Browse files
authored
Add example background script for BusinessTimeUtils
This script demonstrates the usage of BusinessTimeUtils for adding working hours, calculating working minutes between two dates, finding the next open time, and checking if the current time is within the schedule.
1 parent 5fd7979 commit 9709c14

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Background Script demo for BusinessTimeUtils
2+
(function() {
3+
var SCHEDULE_SYS_ID = 'PUT_YOUR_SCHEDULE_SYS_ID_HERE';
4+
var TZ = 'Europe/London';
5+
6+
var util = new BusinessTimeUtils();
7+
8+
var start = new GlideDateTime(); // now
9+
var addRes = util.addWorkingHours(SCHEDULE_SYS_ID, 16, start, TZ);
10+
gs.info('Add 16h ok=' + addRes.ok + ', due=' + (addRes.due ? addRes.due.getDisplayValue() : addRes.message));
11+
12+
var end = new GlideDateTime(addRes.due || start);
13+
var diffRes = util.workingMinutesBetween(SCHEDULE_SYS_ID, start, end, TZ);
14+
gs.info('Working minutes between start and due: ' + diffRes.minutes);
15+
16+
var openRes = util.nextOpen(SCHEDULE_SYS_ID, new GlideDateTime(), TZ);
17+
gs.info('Next open ok=' + openRes.ok + ', at=' + (openRes.nextOpen ? openRes.nextOpen.getDisplayValue() : openRes.message));
18+
19+
var inRes = util.isInSchedule(SCHEDULE_SYS_ID, new GlideDateTime(), TZ);
20+
gs.info('Is now in schedule: ' + inRes.inSchedule);
21+
})();

0 commit comments

Comments
 (0)