Private
constructorPrivate
Readonly
millisecondsAdds another duration to this duration.
The other duration to add.
A new Duration object representing the sum.
const duration1 = Duration.hours(12);
const duration2 = Duration.minutes(30);
const sum = duration1.add(duration2);
console.log(sum.toMinutes());
// Output: 750
Compares this duration with another duration.
The other duration to compare.
-1 if this duration is less than the other, 0 if they are equal, 1 if this duration is greater.
const duration1 = Duration.days(1);
const duration2 = Duration.hours(24);
console.log(duration1.compareTo(duration2)); // Output: 0
Divides this duration by a scalar divisor.
The scalar divisor.
A new Duration object representing the quotient.
Thrown if the divisor is zero.
const duration = Duration.hours(1);
const divided = duration.divide(2);
console.log(divided.toMinutes());
// Output: 30
Checks if this duration is equal to another duration.
The other duration to compare.
True if the durations are equal, false otherwise.
const duration1 = Duration.hours(5);
const duration2 = Duration.hours(5);
console.log(duration1.equals(duration2)); // Output: true
Checks if this duration is greater than another duration.
The other duration to compare.
True if this duration is greater than the other, false otherwise.
Checks if this duration is less than another duration.
The other duration to compare.
True if this duration is less than the other, false otherwise.
const duration1 = Duration.seconds(10);
const duration2 = Duration.seconds(20);
console.log(duration1.lessThan(duration2)); // Output: true
Multiplies this duration by a scalar factor.
The scalar factor.
A new Duration object representing the product.
const duration = Duration.minutes(10);
const multiplied = duration.multiply(2);
console.log(multiplied.toMinutes());
// Output: 20
Splits this duration into days, hours, minutes, seconds, and nanoseconds and executes the given action with these components. The result of the action is returned.
The result of the action.
const duration = Duration.seconds(3600);
const result = duration.runIt((days, hours, minutes, seconds, nanoseconds) => {
return `${days}d ${hours}h ${minutes}m ${seconds}s ${nanoseconds}ns`;
});
console.log(result);
// Output: 0d 1h 0m 0s 0ns
Subtracts another duration from this duration.
The other duration to subtract.
A new Duration object representing the difference.
const duration1 = Duration.hours(12);
const duration2 = Duration.minutes(30);
const difference = duration1.subtract(duration2);
console.log(difference.toMinutes());
// Output: 630
Splits this duration into days, hours, minutes, seconds, and nanoseconds.
An object with properties for days, hours, minutes, seconds, and nanoseconds.
const duration = Duration.days(2).add(Duration.hours(12));
const components = duration.toComponents();
console.log(components);
// Output: { days: 2, hours: 12, minutes: 0, seconds: 0, nanoseconds: 0 }
Converts the duration to an object with properties for each time unit.
An object with properties for nanoseconds, microseconds, milliseconds, seconds, minutes, hours, and days.
const duration = Duration.seconds(123);
const durationObject = duration.toObject();
console.log(durationObject);
// Output: { nanoseconds: 123000000000, microseconds: 123000000, milliseconds: 123000, seconds: 123, minutes: 2, hours: 0, days: 0 }
Static
daysStatic
hoursStatic
microsecondsStatic
millisecondsStatic
minutesStatic
nanosecondsStatic
secondsGenerated using TypeDoc
Represents a duration of time with support for various units (nanoseconds, microseconds, milliseconds, seconds, minutes, hours, and days).
Example
Since
version 1.1.0
Author
Manuel Santos ney.br.santos@gmail.com