Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The objects of this server class store duration as a date and time from starting with January 1, 1970, 00:00:00.

SimpleDuration(duration)


Instantiates a new empty SimpleDuration object.


Parameter(s):

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



Example:

Code Block
languagejs
themeEclipse
titleSimpleDuration
linenumberstrue
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 adds SimpleDuration object to the current SimpleDuration object sums two SimpleDuration objects and returns the result.


Parameter(s):

NameTypeMandatoryDefault Value
durationSimpleDurationYN


Return:

TypeDescription
SimpleDurationThe sum of two SimpleDuration objects.


Example:

Code Block
languagejs
themeEclipse
titleadd
linenumberstrue
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


getByFormat(format)


This method returns allows to get the duration value of the duration in a specified the format you need.


Parameter(s):

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


Return:

TypeDescription
StringSimpleDuration object


Example:

Code Block
languagejs
themeEclipse
titlegetByFormat
linenumberstrue
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 returns the allows to get the duration value in number of the days of the duration.


Return:

TypeDescription
IntegerThe number of the days.


Example:

Code Block
languagejs
themeEclipse
titlegetDayPart
linenumberstrue
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 returns allows to get the number of the days, hours, and minutes of from the durationSimpleDuration object.


Return:

TypeDescription
StringThe number of the days, hours and minutes.


Example:

Code Block
languagejs
themeEclipse
titlegetDisplayValue
linenumberstrue
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:

TypeDescription
IntegerThe duration value in seconds.


Example:

Code Block
languagejs
themeEclipse
titlegetDurationSeconds
linenumberstrue
const downtimeDurationduration = new SimpleDuration('10:00:00');
ss.info(downtimeDurationduration.getDurationSeconds());
//Info: 36000

getDurationValue()


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


Return:

TypeDescription
StringThe duration value.


Example:

Code Block
languagejs
themeEclipse
titlegetDurationValue
linenumberstrue
const downtimeDurationduration = new SimpleDuration(current.downtime / 10007200);
ss.info(downtimeDurationduration.getDurationValue());
// Info: 1 0002:00:00


getRoundedDayPart()


This method returns the rounded number of days taking into account the quantity of hours in the SimpleDuration object. If the number of hours is more than 12, then round the method rounds the value up. Otherwise, round it rounds the value down.


Return:

TypeDescription
IntegerThe rounded number of days.


Example:

Code Block
languagejs
themeEclipse
titlegetRoundedDayPart
linenumberstrue
const timeLeftDurationduration = new SimpleDuration(current.time_left); // '5 12:52:22');
ss.info(timeLeftDurationduration.getRoundedDayPart()); 
//Info: 6

getValue()


This method returns the internal date and time value of in the SimpleDuration objectinternal format.

SimpleDuration objects store

the

duration as a date and time

past January

starting with January 1, 1970, 00:00:00.


Return:

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


Example:

Code Block
languagejs
themeEclipse
titlegetValue
linenumberstrue
const oneDurationduration = new SimpleDuration('10 15:00:00');
ss.info(oneDurationduration.getValue());
//Info: 1970-01-11 15:00:00

Example 2:

Code Block
languagejs
themeEclipse
titlegetValue
linenumberstrue
const myUserId = ss.getUserId();
const timestamp = Number(myUserId.slice(0, 10)); // User created at
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):

NameTypeMandatoryDefault Value
durationStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetDisplayValue
linenumberstrue
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 'YYYYY-mMM-d HDD hh:imm:sss' format.


Parameter(s):

NameTypeMandatoryDefault Value
dateTimeStringYN
dateTimeSimpleDateTimeYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetValue
linenumberstrue
const nowPointDurationdurationOne = new SimpleDuration();
nowPointDurationdurationOne.setValue(new SimpleDateTime().getValue('2019-08-01 09:00:00');
ss.info(durationOne.getByFormat());
const durationTwo = new SimpleDuration();
durationTwo.setValue(new SimpleDateTime('2019-09-05 12:00:00'));
ss.info(nowPointDurationdurationTwo.getDisplayValuegetByFormat());
// Info: 18578 days 16 hours 32 minutes 24 seconds2019-08-01 09:00:00
// Info: 2019-09-05 12:00:00


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:

Code Block
languagejs
themeEclipse
titlesubtract
linenumberstrue
if (current.actual_downtime > current.planned_downtime) {
  const actualValuedurationOne = new SimpleDuration(current.actual_downtime / 1000);
durationOne.setValue('2019-11-08 20:01:58');
  const plannedValuedurationTwo = new SimpleDuration(current.planned_downtime / 10003600);
  const deltaValuedatetime = actualValuedurationOne.subtract(plannedValuedurationTwo);
  if (deltaValue.getDurationSeconds() > 300) { // more than 5 minutes
    ss.eventQueue('notify.change_manager', current, current.assigned_user.getValue('manager'ss.info(datetime.getByFormat());
//  }
}Info: 2019-11-08 19:01:58


Table of Contents
absoluteUrltrue
classfixedPosition