This server class provides methods to operate with the SimpleSchedule objects, for example, getting a schedule name, determining if the current time matches with working time, and returning the difference between two time values.
SimpleSchedule(id, timezoneTitle)
his This method instantiates a new SimpleSchedule object.
Parameter(s):
Name | Type | Mandatory | Default Valuevalue |
---|
id | String | Y | N |
timezoneTitle | String | N | 'UTC' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | schedule |
---|
linenumbers | true |
---|
|
const schedule = new SimpleSchedule('157165292607666710', 'UTC'); |
duration(startDateTime, endDateTime)
This method determines the number of seconds in the schedule between two Datetime values, based on the schedule time zone or, if not specified, the session time zone.
Parameter(s):
Valuevalue |
---|
startDateTime | SimpleDateTime | Y | N |
endDateTime | SimpleDateTime | Y | N |
Return:
Type | Description |
---|
SimpleDuration | The difference between the two time values. |
Example:
Code Block |
---|
|
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()
This method returns the name of the defined schedule.
Return:
Type | Description |
---|
String | A schedule name. |
Example:
Code Block |
---|
|
const schedule = new SimpleSchedule('157165292607666710');
ss.info(schedule.getName()); // Info: 8x5 excluding Russian Holidays |
isInSchedule(datetime)
This method verifies whether the current schedule includes the given datetime or they do not match.
Info |
---|
Excluded schedule segments also return 'true' within checking by this method. |
Parameter(s):
Valuevalue |
---|
datetime | SimpleDateTime | Y | N |
Return:
Type | Description |
---|
Boolean | This method returns |
'' if if the specified datetime is in schedule; otherwise, it returns |
''Example:
Code Block |
---|
language | js |
---|
title | isInSchedule |
---|
|
const nowDatetime = new SimpleDateTime();
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
ss.info(schedule.isInSchedule(nowDatetime)); // Info: false |
isValid()
The method verifies if the specified SimpleSchedule object is valid.
Info |
---|
The object is considered as invalid when: - The schedule passed does not exist.
- The schedule does not contain schedule elements of the working type. The example type for the elements of such schedule is Time Off or Excluded.
In both cases above, the isValid() method returns 'false'. |
Return:
Type | Description |
---|
Boolean | This method returns 'true 'if the schedule is valid; otherwise, it returns 'false'. |
Example:
Code Block |
---|
|
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
ss.info(schedule.isValid()); // Info: true |
isWorkingTime(datetime)
This method checks whether a provided date and time is a working time or not.
Parameter(s):
Name | Type | Mandatory | Default Valuevalue |
---|
datetime | SimpleDateTime | 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:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | isWorkingTime |
---|
linenumbers | true |
---|
|
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)
This method initializes a schedule specified with the sys_id.
Parameter(s):
Valuevalue |
---|
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 |
---|
|
const schedule = new SimpleSchedule();
schedule.load('157165292607666710'); // sys_schedule.sys_id |
setTimeZone(timezoneTitle)
Use this method to define which time zone to apply to the current schedule.
Parameter(s):
Valuevalue |
---|
timezoneTitle | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
title | setTimeZone |
---|
|
const schedule = new SimpleSchedule('157165292607666710'); // sys_schedule.sys_id
schedule.setTimeZone('US/Central'); |
whenNext(datetime, timezoneTitle)
This method returns the number of seconds left until the next schedule element starts.
Parameter(s):
Valuevalue |
---|
datetime | SimpleDateTime | Y | N |
timezoneTitle | | N | '' |
Return:
Type | Description |
---|
SimpleDuration | The SimpleDuration object. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | whenNext |
---|
linenumbers | true |
---|
|
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)
This method determines the time after working seconds value specified in the finalWorkingSeconds parameter passes.
Note |
---|
Note that finalWorkingSeconds parameter does not support negative values. |
Parameter(s):
Valuevalue |
---|
startDate | | Y | N |
finalWorkingSeconds | Integer | Y | N |
Return:
Type | Description |
---|
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), the whenWillExpire() method method returns 'null ' for it. |
Example:
Code Block |
---|
language | js |
---|
title | whenWillExpire |
---|
|
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 |