The objects of this server class store duration as a date and time starting with January with January 1, 1970, 00:00:00.
SimpleDuration(duration)
Instantiates a Use this constructor to instantiate a new SimpleDuration object.
ParameterParameter(s):
Valuevalue |
---|
duration | Integer (seconds) | N | '' |
duration | String (duration |
displayValuein the 'hh:mm:ss' format) | N | '' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleDuration() |
---|
linenumbers | true |
---|
|
const durationOne = new SimpleDuration(3600);
const durationTwo = new SimpleDuration('00:30:00'); |
add(duration)
This method sums two SimpleDuration objects and returns the resultUse this method to add to the current value the value of another SimpleDuration object. The value of the current object changes. The method returns the sum as a new SimpleDuration object.
Parameter(s):
Valuevalue |
---|
duration | SimpleDuration object | Y | N |
Return:
Type | Description |
---|
SimpleDuration object |
The This method returns the sum of two SimpleDuration objects. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | add() |
---|
linenumbers | true |
---|
|
const durationOne = new SimpleDuration(3600);
const durationTwo = new SimpleDuration('00:30:00');
const totalDuration = durationOne.add(durationTwo);
ss.info(totalDuration.getDurationValue());
// Info: 01:30:00 |
This Use this method allows to get the duration value in the the set format you need.
Parameter(s):
Valuevalue |
---|
format | String | N | 'Y-m-d H:i:s' |
Return:
SimpleDuration objectThis method returns a string in the set format. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getByFormat() |
---|
linenumbers | true |
---|
|
const datetime = new SimpleDateTime('2019-11-12 15:34:13');
const duration = new SimpleDuration(datetime.getNumericValue());
ss.info(duration.getByFormat('j F Y (D) H:i:s'));
// Info: 12 November 2019 (Tue) 15:34:13 |
getDayPart()
This Use this method allows to get the duration value in as a number of full days. For example, if an event lasts 2 days 23:59:59, the method returns 2.
Return:
The This method returns the number of days. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDayPart() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration('02 01:30:00');
ss.info(duration.getDayPart());
// Info: 2 |
getDisplayValue()
This Use this method allows to get the number of days, hours, minutes, and minutes seconds from the SimpleDuration object.
Return:
The This method returns the number of days, hours, and minutes. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDisplayValue() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration(3605);
ss.info(duration.getDisplayValue());
// Info: 1 hour 5 seconds |
getDurationSeconds()
This Use this method returns to return the duration value in seconds.
Return:
The This method returns the duration value in seconds. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDurationSeconds() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration('10:00:00');
ss.info(duration.getDurationSeconds());
//Info: 36000 |
getDurationValue()
This Use this method allows to get the value from the SimpleDuration object in in the 'D d H:i:s' format.
Return:
The This method returns the duration value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDurationValue() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration(7200);
ss.info(duration.getDurationValue());
// Info: 02:00:00 |
getRoundedDayPart()
This Use this method returns to return the number of days, taking into account the quantity of hours in the SimpleDuration object. If the number of hours is more less than 12, the method rounds the value updown. Otherwise, it rounds the value downup.
Return:
The This method returns the rounded number of days. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getRoundedDayPart() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration('5 12:52:22');
ss.info(duration.getRoundedDayPart());
//Info: 6 |
getValue()
This Use this method returns to return the date and time value in the internal format.
The SimpleDuration objects store duration as a date and time starting with January 1, 1970, 00:00:00.
Return:
The This method returns a duration string in the |
object's internal format of the object. |
Example 1:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration('10 15:00:00');
ss.info(duration.getValue());
//Info: 1970-01-11 15:00:00 |
Example 2:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue() |
---|
linenumbers | true |
---|
|
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 Use this method sets to set the value in a the 'd H:i:s' format.
Parameter(s):
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setDisplayValue() |
---|
linenumbers | true |
---|
|
const duration = new SimpleDuration();
duration.setDisplayValue('2 10:00:00');
ss.info(duration.getDisplayValue());
//Info: 2 days 10 hours |
setValue(dateTime)
This Use this method sets to set the value in a the 'YYYY-MM-DD hh:mm:ss' format.
Parameter(s):
Valuevalue |
---|
dateTime | String | Y | N |
dateTime | SimpleDateTime object | 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 durationOne = new SimpleDuration();
durationOne.setValue('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(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.Use this method to subtract the value of another SimpleDuration object from the current value. The value of the current object changes. The method returns the subtraction result as a new SimpleDuration object.
Parameter(s):
Valuevalue |
---|
duration | SimpleDuration object | Y | N |
Return:
Type | Description |
---|
SimpleDuration |
The object | This method returns an object with the subtraction result |
objectExample:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | subtract() |
---|
linenumbers | true |
---|
|
const durationOne = new SimpleDuration();
durationOne.setValue('2019-11-08 20:01:58');
const durationTwo = new SimpleDuration(3600);
const datetime = durationOne.subtract(durationTwo);
ss.info(datetime.getByFormat());
// Info: 2019-11-08 19:01:58 |