You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 52 Next »

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):

NameTypeMandatoryDefault Value
durationInteger (seconds)N''
durationString (duration displayValue)N''



Example:

SimpleDuration
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 sums two SimpleDuration objects and returns the result.


Parameter(s):

NameTypeMandatoryDefault Value
durationSimpleDurationYN


Return:

TypeDescription
SimpleDurationThe sum of two SimpleDuration objects.


Example:

add
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 allows to get the duration value in the format you need.


Parameter(s):

NameTypeMandatoryDefault Value
formatStringN'Y-m-d H:i:s'


Return:

TypeDescription
StringSimpleDuration object


Example:

getByFormat
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 allows to get the duration value in number of days.


Return:

TypeDescription
IntegerThe number of days.


Example:

getDayPart
const downtimeDuration = new SimpleDuration(current.downtime / 1000);
if (+downtimeDuration.getDayPart() > 0) {
  current.attention_required = '1';
  current.update();
}

getDisplayValue()


This method allows to get the number of days, hours, and minutes from the SimpleDuration object.


Return:

TypeDescription
StringThe number of days, hours and minutes.


Example:

getDisplayValue
const plannedDowntimeDuration = new SimpleDuration(current.downtime / 1000);
email.setBody(`Planned downtime: ${plannedDowntimeDuration.getDurationValue()}`);

getDurationSeconds()


This method returns the duration value in seconds.


Return:

TypeDescription
IntegerThe duration value in seconds.


Example:

getDurationSeconds
const downtimeDuration = new SimpleDuration('10:00:00');
ss.info(downtimeDuration.getDurationSeconds());
//Info: 36000

getDurationValue()


This method allows to get the value from the SimpleDuration object in 'D H:i:s' format.


Return:

TypeDescription
StringThe duration value.


Example:

getDurationValue
const downtimeDuration = new SimpleDuration(current.downtime / 1000);
ss.info(downtimeDuration.getDurationValue());
//Info: 1 00: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:

TypeDescription
IntegerThe rounded number of days.


Example:

getRoundedDayPart
const timeLeftDuration = new SimpleDuration(current.time_left); // 5 12:52:22
ss.info(timeLeftDuration.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:

TypeDescription
StringThe duration string in the object's internal format.


Example:

getValue
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):

NameTypeMandatoryDefault Value
durationStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

setDisplayValue
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):

NameTypeMandatoryDefault Value
dateTimeStringYN
dateTimeSimpleDateTimeYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

setValue
const endPointDuration = new SimpleDuration();
endPointDuration.setValue(current.end_datetime);
const nowDuration = new SimpleDuration();
nowDuration.setValue(new SimpleDateTime());
ss.info(endPointDuration.getByFormat());
ss.info(nowDuration.getByFormat());
//Info: 2019-11-08 20:01:58
//Info: 2019-11-11 14:36:10

subtract(duration)


This method subtracts one SimpleDuration object from another and returns the result.


Parameter(s):

NameTypeMandatoryDefault Value
durationSimpleDurationYN


Return:

TypeDescription
SimpleDurationThe subtraction result object.


Example:

subtract
const endPointDuration = new SimpleDuration();
endPointDuration.setValue(current.end_datetime); // '2019-11-08 20:01:58';
const duration = new SimpleDuration(current.duration / 1000); // 4500 (seconds)
const startDatetime = endPointDuration.subtract(duration);
ss.info(startDatetime.getByFormat());
//Info: 2019-11-08 18:46:58

  • No labels