SimpleSchedule
This class provides methods that operate the SimpleSchedule objects. For example, you can get a schedule name, verify that the current time matches with the working time, and return the difference between the two time values.
SimpleSchedule(id, timezoneTitle)
Use this method to instantiate a new SimpleSchedule object.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
id | String | N | N |
timezoneTitle | String | N | 'UTC' |
Example:
const schedule = new SimpleSchedule('157165292607666710', 'UTC');
duration(startDateTime, endDateTime)
Use this method to get the time difference between the startDatetime and endDatetime values, based on the schedule, its time zone or, if not specified, the time zone of the session.
The value passed in the datetime parameter should be in the schedule. To verify that, use the isInSchedule(datetime) method.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
startDateTime | SimpleDateTime object | Y | N |
endDateTime | SimpleDateTime object | Y | N |
Return:
Type | Description |
---|---|
SimpleDuration object | This method returns the difference between the two time values. |
Example:
const startDatetime = new SimpleDateTime('2022-01-25 08:00:00');
const endDatetime = new SimpleDateTime('2022-01-29 08:00:00');
const schedule = new SimpleSchedule('161050499417811121'); // sys_schedule.sys_id
const duration = schedule.duration(startDatetime, endDatetime);
ss.info(duration.getValue()); // Info: 1970-01-02 08:00:00
getName()
Use this method to get the name of the specified schedule.
Return:
Type | Description |
---|---|
String | This method returns a schedule name. |
Example:
const schedule = new SimpleSchedule('157165292607666710');
ss.info(schedule.getName()); // Info: 8x5 excluding Russian Holidays
isInSchedule(datetime)
Use this method to verify that the current schedule includes the given date and time.
This method returns true when verifying excluded schedule segments.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
datetime | SimpleDateTime object | Y | N |
Return:
Type | Description |
---|---|
Boolean | This method returns true if the specified datetime value is in the schedule; otherwise, it returns false. |
Example:
const nowDatetime = new SimpleDateTime();
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
ss.info(schedule.isInSchedule(nowDatetime)); // Info: false
isValid()
Use this method to verify that the specified schedule is valid.
A schedule is considered as invalid when:
- The schedule passed does not exist.
- The schedule does not contain the schedule elements of the working type, for example, Time off or Excluded.
In both cases, the isValid() method returns false.
Return:
Type | Description |
---|---|
Boolean | This method returns true if the schedule is valid; otherwise, it returns false. |
Example:
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
ss.info(schedule.isValid()); // Info: true
isWorkingTime(datetime)
Use this method to verify that the provided date and time is a working time.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
datetime | SimpleDateTime object | Y | N |
Return:
Type | Description |
---|---|
Boolean | This method returns true if the provided date and time is a working time; otherwise, it returns false. |
Example:
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
const firstDatetime = new SimpleDateTime('2020-12-15 05:59:59');
const secondDatetime = new SimpleDateTime('2020-12-15 06:00:00');
ss.info(schedule.isWorkingTime(firstDatetime)); // Info: false
ss.info(schedule.isWorkingTime(secondDatetime)); // Info: true
load(sysId, timezoneTitle)
Use this method to initialize a schedule specified with the ID according to the time zone.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
sysId | String | Y | N |
timezoneTitle | String | N | 'UTC' |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
const schedule = new SimpleSchedule();
schedule.load('157165292607666710'); // sys_schedule.sys_id
setTimeZone(timezoneTitle)
Use this method to set a time zone for 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:
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
schedule.setTimeZone('US/Central');
whenNext(datetime, timezoneTitle)
Use this method to get the time left, as a SimpleDuration object, until the next schedule element begins.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
datetime | SimpleDateTime object | Y | N |
timezoneTitle | String | Y | '' |
Return:
Type | Description |
---|---|
SimpleDuration object | This method returns the SimpleDuration object. It returns null if the schedule is invalid. |
Example:
const startDatetime = new SimpleDateTime();
const schedule = new SimpleSchedule('161050499417811121'); // sys_schedule.sys_id
ss.info('Seconds Left: ' + schedule.whenNext(startDatetime).getDurationSeconds()); // Info: Seconds Left: 6052
whenWillExpire(startDateTime, finalWorkingSeconds)
Use this method to calculate the date and time when the time value set in the finalWorkingSeconds parameter in seconds finishes after the time set in the startDateTime. All calculations are done based on the specified schedule.
The finalWorkingSeconds parameter does not support negative values.
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
startDate | SimpleDateTime object | Y | N |
finalWorkingSeconds | Integer | Y | N |
Return:
Type | Description |
---|---|
SimpleDateTime object | This method returns the SimpleDateTime object. |
If the SimpleSchedule class object is not valid (the isValid() method returns false for this object), the whenWillExpire() method returns null.
Example:
const startDatetime = new SimpleDateTime('2022-01-23 08:00:00');
const finalWorkingSeconds = 5 * 8 * 3600; // duration of 5 eight-hour days in seconds
const schedule = new SimpleSchedule('161050499417811121'); // sys_schedule.sys_id
ss.info(schedule.whenWillExpire(startDatetime, finalWorkingSeconds).getValue()); // Info: 2022-01-28 18:30:00