The objects of this server class store duration as a date and time starting with January 1, 1970, 00:00:00.
SimpleDuration(duration)
Instantiates a new SimpleDuration object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
duration | Integer (seconds) | N | '' |
duration | String (duration displayValue) | N | '' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleDuration |
---|
linenumbers | true |
---|
|
const downtimeDurationdurationOne = new SimpleDuration(current.downtime / 10003600);
const slackDurationdurationTwo = new SimpleDuration('00:30:00');
const totalDuration = downtimeDuration.add(slackDuration);
email.setBody(`Planned downtime: ${totalDuration.getDurationValue()}`); |
add(duration)
This method sums two SimpleDuration objects and returns the result.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
duration | SimpleDuration | Y | N |
Return:
Type | Description |
---|
SimpleDuration | The sum of two SimpleDuration objects. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | add |
---|
linenumbers | true |
---|
|
const downtimeDurationdurationOne = new SimpleDuration(current.downtime / 10003600);
const slackDurationdurationTwo = new SimpleDuration('00:30:00');
const totalDuration = downtimeDurationdurationOne.add(slackDurationdurationTwo);
emailss.setBody(`Planned downtime: ${info(totalDuration.getDurationValue()}`);
// Info: 01:30:00 |
This method allows to get the duration value in the format you need.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
format | String | N | 'Y-m-d H:i:s' |
Return:
Type | Description |
---|
String | SimpleDuration object |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getByFormat |
---|
linenumbers | true |
---|
|
const processingPointdatetime = new SimpleDateTime('2019-11-12 15:34:13');
const processingDurationduration = new SimpleDuration(processingPointdatetime.getNumericValue());
ss.info(`Calculation processed at:\n${processingDurationduration.getByFormat('j F Y (D) H:i:s')}`);
// Info: Calculation processed at:
//12 November 2019 (Tue) 15:34:13 |
getDayPart()
This method allows to get the duration value in number of days.
Return:
Type | Description |
---|
Integer | The number of days. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDayPart |
---|
linenumbers | true |
---|
|
const downtimeDurationduration = new SimpleDuration(current.downtime / 1000'02 01:30:00');
if (+downtimeDurationss.info(duration.getDayPart() > 0) {
current.attention_required = '1';
// current.update();
}Info: 2 |
getDisplayValue()
This method allows to get the number of days, hours, and minutes from the SimpleDuration object.
Return:
Type | Description |
---|
String | The number of days, hours and minutes. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDisplayValue |
---|
linenumbers | true |
---|
|
const plannedDowntimeDurationduration = new SimpleDuration(current.downtime / 10003605);
emailss.setBody(`Planned downtime: ${plannedDowntimeDuration.getDurationValue()}`);info(duration.getDisplayValue());
// Info: 1 hour 5 seconds |
getDurationSeconds()
This method returns the duration value in seconds.
Return:
Type | Description |
---|
Integer | The duration value in seconds. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDurationSeconds |
---|
linenumbers | true |
---|
|
const downtimeDurationduration = new SimpleDuration('10:00:00');
ss.info(downtimeDurationduration.getDurationSeconds());
//Info: 36000 |
getDurationValue()
This method allows to get the value from the SimpleDuration object in 'D H:i:s' format.
Return:
Type | Description |
---|
String | The duration value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDurationValue |
---|
linenumbers | true |
---|
|
const downtimeDurationduration = new SimpleDuration(current.downtime / 10007200);
ss.info(downtimeDurationduration.getDurationValue());
// Info: 1 0002:00:00 |
getRoundedDayPart()
This method returns the number of days taking into account the quantity of hours in the SimpleDuration object. If the number of hours is more than 12, the method rounds the value up. Otherwise, it rounds the value down.
Return:
Type | Description |
---|
Integer | The rounded number of days. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getRoundedDayPart |
---|
linenumbers | true |
---|
|
const timeLeftDurationduration = new SimpleDuration(current.time_left); // '5 12:52:22');
ss.info(timeLeftDurationduration.getRoundedDayPart());
//Info: 6 |
getValue()
This method returns the date and time value in the internal format.
SimpleDuration objects store duration as a date and time starting with January 1, 1970, 00:00:00.
Return:
Type | Description |
---|
String | The duration string in the object's internal format. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue |
---|
linenumbers | true |
---|
|
const oneDurationduration = new SimpleDuration('10 15:00:00');
ss.info(oneDurationduration.getValue());
//Info: 1970-01-11 15:00:00 |
Example 2:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue |
---|
linenumbers | true |
---|
|
const userId = '155931135900000001';
const timestamp = +Number(userId.slice(0, 10));
const duration = new SimpleDuration(timestamp);
ss.info(duration.getValue());
// Info: 2019-05-31 14:02:39 |
setDisplayValue(duration)
This method sets the value in a 'd H:i:s' format.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
duration | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setDisplayValue |
---|
linenumbers | true |
---|
|
const simpleDurationduration = new SimpleDuration();
simpleDurationduration.setDisplayValue('2 10:00:00');
ss.info(simpleDurationduration.getDisplayValue());
//Info: 2 days 10 hours |
setValue(dateTime)
This method sets the value in a a 'YYYYY-mMM-d HDD hh:imm:sss' format.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | String | Y | N |
dateTime | SimpleDateTime | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setValue |
---|
linenumbers | true |
---|
|
const endPointDurationdurationOne = new SimpleDuration();
endPointDurationdurationOne.setValue(current.end_datetime('2019-08-01 09:00:00');
ss.info(durationOne.getByFormat());
const nowDurationdurationTwo = new SimpleDuration();
nowDurationdurationTwo.setValue(new SimpleDateTime('2019-09-05 12:00:00'));
ss.info(endPointDuration.getByFormat());
ss.info(nowDurationdurationTwo.getByFormat());
// Info: 2019-1108-0801 2009:0100:5800
// Info: 2019-1109-1105 1412:3600:1000 |
subtract(duration)
This method subtracts one SimpleDuration object from another and returns the result.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
duration | SimpleDuration | Y | N |
Return:
Type | Description |
---|
SimpleDuration | The subtraction result object. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | subtract |
---|
linenumbers | true |
---|
|
const endPointDurationdurationOne = new SimpleDuration();
endPointDurationdurationOne.setValue(current.end_datetime); // '2019-11-08 20:01:58');
const durationdurationTwo = new SimpleDuration(current.duration / 10003600); // 4500 (seconds)
const startDatetimedatetime = endPointDurationdurationOne.subtract(durationdurationTwo);
ss.info(startDatetimedatetime.getByFormat());
// Info: 2019-11-08 1819:4601:58 |