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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
duration | Integer (seconds) | N | '' |
duration | String (duration displayValue) | N | '' |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_durationconst durationOne = new SimpleDuration(3600); const durationTwo = new SimpleDuration('0100:0030:00'); |
add(duration)
This method adds SimpleDuration object to the current SimpleDuration object 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_durationdurationOne = new SimpleDuration('2 10:00:00'3600); var simple_duration_1const durationTwo = new SimpleDuration('0100:0030:00'); varconst resulttotalDuration = simple_durationdurationOne.add(simple_duration_1durationTwo); ss.info(resulttotalDuration.getDisplayValuegetDurationValue() ); // 2 days 11 hoursInfo: 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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
format | String | N | 'Y-m-d H:i:s' |
Return:
Type | Description |
---|---|
String | SimpleDuration object |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_durationdatetime = new SimpleDurationSimpleDateTime('2 10:00:002019-11-12 15:34:13'); const duration = new SimpleDuration(datetime.getNumericValue()); ss.info(simple_duration.getByFormat('h:mj F Y (D) H:i:s') ); // 10:01 Info: 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:
Type | Description |
---|---|
Integer | The number of the days. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_duration = new SimpleDuration('202 1001:0030:00'); ss.info(simple_duration.getDayPart() ); // Info: 2 |
getDisplayValue()
This method returns allows to get the number of the days, hours, and minutes of from the durationSimpleDuration object.
Return:
Type | Description |
---|---|
String | The number of the days, hours and minutes. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_duration = new SimpleDuration('10 10:00:00'3605); ss.info(simple_duration.getDisplayValue() ); //10 days 10 hours 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
letconst simple_duration = new SimpleDuration('10 10:00:00'); ss.info(simple_duration.getDurationSeconds() ); //Info: 90000036000 |
getDurationValue()
This method returns allows to get the duration value in from the SimpleDuration object in 'D H:i:s' format.
Return:
Type | Description |
---|---|
String | The duration value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_duration = new SimpleDuration('10 10:00:00'7200); ss.info(simple_duration.getDurationValue() ); //10 Info: 1002: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:
Type | Description |
---|---|
Integer | The rounded number of days. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_duration = new SimpleDuration('105 1012:0052:0022'); ss.info(simple_duration.getRoundedDayPart() ); // 10 | ||||||||
Code Block | ||||||||
| ||||||||
var simple_duration = new SimpleDuration('10 14:00:00'); ss.info(simple_duration.getRoundedDayPart() ); // 11 //Info: 6 |
getValue()
This method returns the internal date and time value of in the SimpleDuration objectinternal format.
SimpleDuration objects store
theduration as a date and time
past Januarystarting with January 1, 1970, 00:00:00.
Return:
Type | Description |
---|---|
String | The duration string in the object's internal format. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_duration = new SimpleDuration('10 15:00:00'); ss.info(simple_duration.getValue() ); //Info: 1970-01-11 15:00:00 |
Example 2:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
duration | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_duration = new SimpleDuration(); simple_duration.setDisplayValue('2 10:00:00'); ss.info(simple_duration.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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_durationdurationOne = new SimpleDuration(); simple_durationdurationOne.setValue('2 102019-08-01 09:00:00'); ss.info(simple_duration.getDisplayValue() );durationOne.getByFormat()); const durationTwo = new SimpleDuration(); durationTwo.setValue(new SimpleDateTime('2019-09-05 12:00:00')); ss.info(durationTwo.getByFormat()); // Info: 2019-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):
Name | Type | Mandatory | Default Value |
---|---|---|---|
duration | SimpleDuration | Y | N |
Return:
Type | Description |
---|---|
SimpleDuration | The subtraction result object. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
varconst simple_durationdurationOne = new SimpleDuration('10 05:00:00); durationOne.setValue('2019-11-08 20:01:58'); var simple_duration_1const durationTwo = new SimpleDuration('05:00:00'3600); varconst datetime result= simple_duration durationOne.subtract(simple_duration_1durationTwo); ss.info(resultdatetime.getDisplayValuegetByFormat() ); // 10 days Info: 2019-11-08 19:01:58 |
Table of Contents | ||||
---|---|---|---|---|
|