@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
294 lines (293 loc) • 12.8 kB
TypeScript
/**
* A time-based amount of time, such as '34.5 seconds'.
*
* This class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other
* duration-based units, such as minutes and hours. In addition, the DAYS unit can be used and is treated as exactly
* equal to 24 hours, thus ignoring daylight savings effects.
*
* A physical duration could be of infinite length. The duration uses nanosecond resolution with a maximum value of the
* seconds that can be held in a long. This is greater than the current estimated age of the universe.
*
* The range of a duration requires the storage of a number larger than a long. To achieve this, the class stores a long
* representing seconds and an integer representing nanosecond-of-second, which will always be between 0 and 999,999,999.
* The model is of a directed duration, meaning that the duration may be negative.
*
* The duration is measured in "seconds", but these are not necessarily identical to the scientific "SI second"
* definition based on atomic clocks. This difference only impacts durations measured near a leap-second and should not
* affect most applications.
*
* This is a value-based class; use of identity-sensitive operations on instances of Duration may have unpredictable
* results and should be avoided. The equals method should be used for comparisons.
*/
export declare class Duration {
readonly seconds: number;
readonly nanos: number;
/**
* A constant for a duration of zero.
*/
static readonly ZERO: Duration;
/**
* A constant for a duration of forever.
*/
static readonly FOREVER: Duration;
/**
* Creates a new instance of Duration with the specified number of seconds and nanoseconds.
* This is a private constructor and not intended to be called directly.
*
* @param seconds - the number of seconds
* @param nanos - the number of nanoseconds
*/
private constructor();
/**
* Checks if this duration is zero.
*
* @returns true if this duration is zero; false otherwise.
*/
isZero(): boolean;
/**
* Checks if this duration is negative.
*
* @returns true if this duration is negative; false otherwise.
*/
isNegative(): boolean;
/**
* Creates a new Duration instance with the specified number of seconds. The current number of nanoseconds in this
* duration is preserved.
*
* @param seconds - the number of seconds for the new duration
* @returns a new Duration instance with the specified number of seconds.
*/
withSeconds(seconds: number): Duration;
/**
* Creates a new Duration instance with the specified number of nanoseconds. The current number of seconds in this
* duration is preserved.
*
* @param nanos - the number of nanoseconds for the new duration
* @returns a new Duration instance with the specified number of nanoseconds.
*/
withNanos(nanos: number): Duration;
/**
* Creates a new Duration instance by adding the specified duration to this duration.
*
* @param other - the duration to add
* @returns a new Duration instance with the sum of this duration and the specified duration.
*/
plus(other: Duration): Duration;
/**
* Creates a new Duration instance by adding the specified number of days to this duration.
*
* @param daysToAdd - the number of days to add
* @returns a new Duration instance with the sum of this duration and the specified number of days.
*/
plusDays(daysToAdd: number): Duration;
/**
* Creates a new Duration instance by adding the specified number of hours to this duration.
*
* @param hoursToAdd - the number of hours to add
* @returns a new Duration instance with the sum of this duration and the specified number of hours.
*/
plusHours(hoursToAdd: number): Duration;
/**
* Creates a new Duration instance by adding the specified number of minutes to this duration.
*
* @param minutesToAdd - the number of minutes to add
* @returns a new Duration instance with the sum of this duration and the specified number of minutes.
*/
plusMinutes(minutesToAdd: number): Duration;
/**
* Creates a new Duration instance by adding the specified number of seconds to this duration.
*
* @param secondsToAdd - the number of seconds to add
* @returns a new Duration instance with the sum of this duration and the specified number of seconds.
*/
plusSeconds(secondsToAdd: number): Duration;
/**
* Creates a new Duration instance by adding the specified number of milliseconds to this duration.
*
* @param millisToAdd - the number of milliseconds to add
* @returns a new Duration instance with the sum of this duration and the specified number of milliseconds.
*/
plusMillis(millisToAdd: number): Duration;
/**
* Creates a new Duration instance by adding the specified number of nanoseconds to this duration.
*
* @param nanosToAdd - the number of nanoseconds to add
* @returns a new Duration instance with the sum of this duration and the specified number of nanoseconds.
*/
plusNanos(nanosToAdd: number): Duration;
/**
* Creates a new Duration instance by subtracting the specified duration from this duration.
*
* @param other - the duration to subtract
* @returns a new Duration instance with the difference of this duration and the specified duration.
*/
minus(other: Duration): Duration;
/**
* Creates a new Duration instance by subtracting the specified number of days from this duration.
*
* @param daysToSubtract - the number of days to subtract
* @returns a new Duration instance with the difference of this duration and the specified number of days.
*/
minusDays(daysToSubtract: number): Duration;
/**
* Creates a new Duration instance by subtracting the specified number of hours from this duration.
*
* @param hoursToSubtract - the number of hours to subtract
* @returns a new Duration instance with the difference of this duration and the specified number of hours.
*/
minusHours(hoursToSubtract: number): Duration;
/**
* Creates a new Duration instance by subtracting the specified number of minutes from this duration.
*
* @param minutesToSubtract - the number of minutes to subtract
* @returns a new Duration instance with the difference of this duration and the specified number of minutes.
*/
minusMinutes(minutesToSubtract: number): Duration;
/**
* Creates a new Duration instance by subtracting the specified number of seconds from this duration.
*
* @param secondsToSubtract - the number of seconds to subtract
* @returns a new Duration instance with the difference of this duration and the specified number of seconds.
*/
minusSeconds(secondsToSubtract: number): Duration;
/**
* Creates a new Duration instance by subtracting the specified number of milliseconds from this duration.
*
* @param millisToSubtract - the number of milliseconds to subtract
* @returns a new Duration instance with the difference of this duration and the specified number of milliseconds.
*/
minusMillis(millisToSubtract: number): Duration;
/**
* Creates a new Duration instance by subtracting the specified number of nanoseconds from this duration.
*
* @param nanosToSubtract - the number of nanoseconds to subtract
* @returns a new Duration instance with the difference of this duration and the specified number of nanoseconds.
*/
minusNanos(nanosToSubtract: number): Duration;
/**
* Converts this duration to days.
*
* @returns the number of days in this duration.
*/
toDays(): number;
/**
* Converts this duration to hours.
*
* @returns the number of hours in this duration.
*/
toHours(): number;
/**
* Converts this duration to minutes.
*
* @returns the number of minutes in this duration.
*/
toMinutes(): number;
/**
* Converts this duration to milliseconds.
*
* @returns the number of milliseconds in this duration.
*/
toMillis(): number;
/**
* Converts this duration to nanoseconds.
*
* @returns the number of nanoseconds in this duration.
*/
toNanos(): number;
/**
* Compares this duration to the specified duration.
*
* @param other - the duration being compared to this duration
* @returns true if the two durations are equal; false otherwise.
*/
equals(other: Duration): boolean;
/**
* Compares this duration to the specified duration.
*
* @param other - the duration being compared to this duration
* @returns a negative value if this duration is less than the specified duration, a positive value if this duration
* is greater than the specified duration, or zero if the two durations are equal.
*/
compareTo(other: Duration): number;
/**
* Creates a new Duration instance representing the specified number of days.
*
* @param days - the number of days
* @returns a new Duration instance representing the specified number of days.
*/
static ofDays(days: number): Duration;
/**
* Creates a new Duration instance representing the specified number of hours.
*
* @param hours - the number of hours
* @returns a new Duration instance representing the specified number of hours.
*/
static ofHours(hours: number): Duration;
/**
* Creates a new Duration instance representing the specified number of minutes.
*
* @param minutes - the number of minutes
* @returns a new Duration instance representing the specified number of minutes.
*/
static ofMinutes(minutes: number): Duration;
/**
* Creates a new Duration instance representing the specified number of seconds.
*
* @param seconds - the number of seconds
* @returns a new Duration instance representing the specified number of seconds.
*/
static ofSeconds(seconds: number): Duration;
/**
* Creates a new Duration instance representing the specified number of seconds adjusted by a number of nanoseconds.
*
* @param seconds - the number of seconds
* @param nanoAdjustment - the number of nanoseconds by which to adjust the seconds
* @returns a new Duration instance representing the specified number of seconds adjusted by the specified number of nanoseconds.
*/
static ofSecondsAdjusted(seconds: number, nanoAdjustment: number): Duration;
/**
* Creates a new Duration instance representing the specified number of milliseconds.
*
* @param millis - the number of milliseconds
* @returns a new Duration instance representing the specified number of milliseconds.
*/
static ofMillis(millis: number): Duration;
/**
* Creates a new Duration instance representing the specified number of nanoseconds.
*
* @param nanos - the number of nanoseconds
* @returns a new Duration instance representing the specified number of nanoseconds.
*/
static ofNanos(nanos: number): Duration;
/**
* Private utility method to create a new Duration instance representing the specified number of seconds and
* nanoseconds.
*
* @param seconds - the number of seconds
* @param nanoAdjustment - the number of nanoseconds
* @returns a new Duration instance representing the specified number of seconds and nanoseconds.
*/
private static create;
/**
* Private utility method to create a new Duration instance by adding the specified number of seconds and nanoseconds.
*
* @param secondsToAdd - the number of seconds to add
* @param nanosToAdd - the number of nanoseconds to add
* @returns a new Duration instance with the sum of this duration and the specified number of seconds and nanoseconds.
*/
private plusExact;
/**
* Private utility method to validate the specified number of nanoseconds.
*
* @param nanos - the number of nanoseconds to validate
* @returns true if the specified number of nanoseconds is valid; false otherwise.
*/
private static isValidNanos;
/**
* Private utility method to validate the specified number of nanoseconds.
*
* @param nanos - the number of nanoseconds to validate
* @throws IllegalArgumentError if the specified number of nanoseconds is invalid.
*/
private static checkValidNanos;
}