This server class provides methods for performing operations on SimpleSchedule objects, such as getting schedule name; determining methods are designed to work with the SimpleSchedule objects. You can use them, for example, to get a schedule name, to verify if the current time value is working time or not or setting time zone for the schedule.
duration(startDate, endDatematches with the working time, and return the difference between the two time values.
SimpleSchedule(id, timezoneTitle)
Use this cinstructor to instantiate a new SimpleSchedule object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
id | String | N | N |
timezoneTitle | String | N | 'UTC' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleSchedule |
---|
linenumbers | true |
---|
|
const schedule = new SimpleSchedule('157165292607666710', 'UTC'); |
duration(startDateTime, endDateTime)
This method determines elapsed the time difference in seconds in the schedule between two date-time SimpleDateTime values, using based on the schedule time zone or, if not specified, the session time zonethe session time zone.
Note |
---|
The passed SimpleDateTime value should be in the schedule. For verification, use the isInSchedule(datetime) method. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
startDateTimestartDate | SimpleDateTime object | Y | N |
endDateTimeendDate | SimpleDateTime | Y | N |
Return:
Type | Description |
---|
SimpleDuration | The difference between the two time values |
(in seconds)
Example:
Code Block |
---|
|
letconst startDatestartDatetime = new SimpleDateTime('20192022-1001-25 08:00:00');
letconst endDateendDatetime = new SimpleDateTime('20192022-1001-29 08:00:00');
letconst simple_schedule = new SimpleSchedule('1161050499417811121',); 'Europe/Moscow');
let// sys_schedule.sys_id
const duration = simple_schedule.duration(startDatestartDatetime, endDateendDatetime);
ss.info(duration.getValue()); |
Initializes a schedule by the sys_id.
Parameter(s):
Name | Type |
---|
sysId | Integer |
// Info: 1970-01-02 08:00:00 |
getName()
This method returns the name of the defined schedule.
timeZone | String (empty string by default)
Return:
Void | This method does not return a value
Example:
Code Block |
---|
language | js |
---|
title | loadgetName |
---|
|
letconst simple_schedule = new SimpleSchedule('157165292607666710');
simple_ss.info(schedule.loadgetName('1')); |
Returns a schedule name.
// Info: 8x5 excluding Russian Holidays |
isInSchedule(datetime)
This method checks whether the current schedule includes the given datetime or they do not match.
Info |
---|
Excluded schedule segments will also return 'true' within checking by this method. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
datetime | SimpleDateTime | Y | N |
Return:
String | The schedule nameBoolean | This method returns 'true' if the specified datetime is in schedule; otherwise, it returns 'false'. |
Example:
Code Block |
---|
language | js |
---|
title | getName | isInSchedule |
---|
|
const nowDatetime = new SimpleDateTime();
const let simple_schedule = new SimpleSchedule('1157165292607666710',); 'Europe/Moscow');// sys_schedule.sys_id
ss.info(simple_schedule.getNameisInSchedule(nowDatetime)); // Info: false |
isValid()
Determines The method checks if the specified SimpleSchedule object is valid.
Info |
---|
The object is considered as invalid when: - The schedule
|
is valid- passed does not exist.
- The schedule does not contain schedule elements of the working type. The example type for elements of such schedule is Time Off or Excluded.
In both cases above, the isValid() method returns 'false'. |
Return:
True This method returns 'true' if the schedule is valid; otherwise, it returns 'false'. |
Example:
Code Block |
---|
|
letconst simple_schedule = new SimpleSchedule('1157165292607666710',); 'Europe/Moscow');// sys_schedule.sys_id
ss.info(simple_schedule.isValid()); |
isWorkingTime(datetime)
This method checks whether a provided date and time is a working time or notDetermines if the given datetime is within the current schedule.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
time
Return:
True if the specified datetime is in schedule; otherwise false. | Example:This method returns 'true' if provided date and time is a working time; otherwise, it returns 'false'. |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | isInSchedule | isWorkingTime |
---|
linenumbers | true |
---|
|
const schedulelet time = new SimpleDateTimeSimpleSchedule('157165292607666710');
let simple_schedule // sys_schedule.sys_id
const firstDatetime = new SimpleScheduleSimpleDateTime('1', 'Europe/Moscow2020-12-15 05:59:59');
const secondDatetime = new SimpleDateTime('2020-12-15 06:00:00');
ss.info(simple_schedule.isInSchedule(time)); |
schedule.isWorkingTime(firstDatetime)); // Info: false
ss.info(schedule.isWorkingTime(secondDatetime)); // Info: true |
load(sysId, timezoneTitle)
This method initializes a schedule specified with the sys_id.
Setting a time zone
Parameter(s):
timeZone | String |
| Mandatory | Default Value |
---|
sysId | String | Y | N |
timezoneTitle | String (empty string by default) | N | '' |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
title | setTimeZoneload |
---|
|
letconst timeschedule = new SimpleDateTimeSimpleSchedule();
schedule.load('157165292607666710'); // sys_schedule.sys_id |
setTimeZone(timezoneTitle)
This method defines which time zone is to be applied to the current schedule.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
timezoneTitle | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
title | setTimeZone |
---|
|
const let simple_schedule = new SimpleSchedule('1157165292607666710',); 'Europe/Moscow');
simple_// sys_schedule.sys_id
schedule.setTimeZone('US/Central'); |
whenWillExpirewhenNext(
startDatedatetime,
finalWorkingSecondstimezoneTitle)
This method
determines the time after working seconds value specified in the finalWorkingSeconds parameter passesreturns the number of seconds left until the next schedule element starts.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
datetimestartDate | SimpleDateTime | finalWorkingSeconds | | Y | N |
timezoneTitle | | N | '' | Integer |
Return:
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | whenNext |
---|
linenumbers | truewhenWillExpire |
---|
|
letconst startDatestartDatetime = new SimpleDateTime('2019-10-25 08:00:00');
let finalWorkingSeconds = 12345;
let simple_const schedule = new SimpleSchedule('1161050499417811121',); 'Europe/Moscow');// sys_schedule.sys_id
ss.info(simple_schedule.whenWillExpire(startDate, finalWorkingSeconds)); |
Determines how much time (in seconds) is left until next schedule item starts'Seconds Left: ' + schedule.whenNext(startDatetime).getDurationSeconds()); // Info: Seconds Left: 6052 |
whenWillExpire(startDateTime, finalWorkingSeconds)
This method determines the time after working seconds value specified in the finalWorkingSeconds parameter passes.
Note |
---|
Please note that finalWorkingSeconds parameter does not support negative values. |
Parameter(s):
timeMandatory | Default Value |
---|
startDate | |
timeZone | String | Y | N |
finalWorkingSeconds | Integer | Y | N |
Return:
Integer | The number in milliseconds |
---|
SimpleDateTime object or 'null' | This method returns the SimpleDateTime object. |
Note |
---|
If the SimpleSchedule class object is not valid (the isValid() method returns 'false' for this object), then the whenWillExpire() method returns 'null' for it. |
Example:
Code Block |
---|
language | js |
---|
title | whenNextwhenWillExpire |
---|
|
letconst startDatestartDatetime = new SimpleDateTime('20192022-1001-2523 08:00:00');
let simple_schedule const finalWorkingSeconds = 5 * 8 * 3600; // duration of 5 eight-hour days in seconds
const schedule = new SimpleSchedule('1161050499417811121',); 'Europe/Moscow');// sys_schedule.sys_id
ss.info(simple_schedule.whenNext(startDatewhenWillExpire(startDatetime, finalWorkingSeconds).getValue()); // Info: 2022-01-28 18:30:00 |