You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 49 Next »
The objects of this server class store duration as a date and time from January 1, 1970, 00:00:00.
SimpleDuration(duration)
Instantiates a new empty SimpleDuration object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
duration | Integer (seconds) | N | '' |
duration | String (duration displayValue) | N | '' |
Example:
const downtimeDuration = new SimpleDuration(current.downtime / 1000); const slackDuration = new SimpleDuration('00:30:00'); const totalDuration = downtimeDuration.add(slackDuration); email.setBody(`Planned downtime: ${totalDuration.getDurationValue()}`);
add(duration)
This method adds SimpleDuration object to the current SimpleDuration object 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:
const downtimeDuration = new SimpleDuration(current.downtime / 1000); const slackDuration = new SimpleDuration('00:30:00'); const totalDuration = downtimeDuration.add(slackDuration); email.setBody(`Planned downtime: ${totalDuration.getDurationValue()}`);
getByFormat(format)
This method returns the value of the duration in a specified format.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
format | String | N | 'Y-m-d H:i:s' |
Return:
Type | Description |
---|---|
String | SimpleDuration object |
Example:
const processingPoint = new SimpleDateTime(); const processingDuration = new SimpleDuration(processingPoint.getNumericValue()); ss.info(`Calculation processed at:\n${processingDuration.getByFormat('j F Y (D) H:i:s')}`); //Info: Calculation processed at: //12 November 2019 (Tue) 15:34:13
getDayPart()
This method returns the number of the days of the duration.
Return:
Type | Description |
---|---|
Integer | The number of the days. |
Example:
const downtimeDuration = new SimpleDuration(current.downtime / 1000); if (+downtimeDuration.getDayPart() > 0) { current.attention_required = '1'; current.update(); }
getDisplayValue()
This method returns the number of the days, hours and minutes of the duration.
Return:
Type | Description |
---|---|
String | The number of the days, hours and minutes. |
Example:
const plannedDowntimeDuration = new SimpleDuration(current.downtime / 1000); email.setBody(`Planned downtime: ${plannedDowntimeDuration.getDurationValue()}`);
getDurationSeconds()
This method returns the duration value in seconds.
Return:
Type | Description |
---|---|
Integer | The duration value in seconds. |
Example:
const downtimeDuration = new SimpleDuration('10:00:00'); ss.info(downtimeDuration.getDurationSeconds()); //Info: 36000
getDurationValue()
This method returns the duration value in 'D H:i:s' format.
Return:
Type | Description |
---|---|
String | The duration value. |
Example:
const downtimeDuration = new SimpleDuration(current.downtime / 1000); ss.info(downtimeDuration.getDurationValue()); //Info: 1 00:00:00
getRoundedDayPart()
This method returns the rounded number of days. If the number of hours is more than 12, then round the value up. Otherwise, round it down.
Return:
Type | Description |
---|---|
Integer | The rounded number of days. |
Example:
const timeLeftDuration = new SimpleDuration(current.time_left); // 5 12:52:22 ss.info(timeLeftDuration.getRoundedDayPart()); //Info: 6
getValue()
This method returns the internal value of the SimpleDuration object.
SimpleDuration objects store the duration as a date and time past January 1, 1970, 00:00:00.
Return:
Type | Description |
---|---|
String | The duration string in the object's internal format. |
Example:
const oneDuration = new SimpleDuration('10 15:00:00'); ss.info(oneDuration.getValue()); //Info: 1970-01-11 15:00:00
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:
const simpleDuration = new SimpleDuration(); simpleDuration.setDisplayValue('2 10:00:00'); ss.info(simpleDuration.getDisplayValue()); //Info: 2 days 10 hours
setValue(dateTime)
This method sets the value in a 'Y-m-d H:i:s' 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:
const nowPointDuration = new SimpleDuration(); nowPointDuration.setValue(new SimpleDateTime().getValue()); ss.info(nowPointDuration.getDisplayValue()); //Info: 18578 days 16 hours 32 minutes 24 seconds
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:
const nowPointDuration = new SimpleDuration(); nowPointDuration.setValue(current.start_datetime); // '2019-11-08 20:01:58'; const downtimeDuration = new SimpleDuration(current.duration / 1000); // 68412 (seconds) const deltaValue = nowPointDuration.subtract(downtimeDuration); ss.info(deltaValue.getByFormat()); //Info: 2019-11-08 01:01:46
- No labels