Package io.opencensus.common
Class Duration
- java.lang.Object
-
- io.opencensus.common.Duration
-
- All Implemented Interfaces:
java.lang.Comparable<Duration>
- Direct Known Subclasses:
AutoValue_Duration
@Immutable public abstract class Duration extends java.lang.Object implements java.lang.Comparable<Duration>
Represents a signed, fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like "day" or "month". Range is approximately +-10,000 years.- Since:
- 0.5
-
-
Constructor Summary
Constructors Constructor Description Duration()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(Duration otherDuration)
Compares thisDuration
to the specifiedDuration
.static Duration
create(long seconds, int nanos)
Creates a new time duration from given seconds and nanoseconds.static Duration
fromMillis(long millis)
Creates a newDuration
from given milliseconds.abstract int
getNanos()
Returns the number of nanoseconds in theDuration
.abstract long
getSeconds()
Returns the number of seconds in theDuration
.long
toMillis()
Converts aDuration
to milliseconds.
-
-
-
Method Detail
-
create
public static Duration create(long seconds, int nanos)
Creates a new time duration from given seconds and nanoseconds.- Parameters:
seconds
- Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive.nanos
- Signed fractions of a second at nanosecond resolution of the span of time. Durations less than one second are represented with a 0 `seconds` field and a positive or negative `nanos` field. For durations of one second or more, a non-zero value for the `nanos` field must be of the same sign as the `seconds` field. Must be from -999,999,999 to +999,999,999 inclusive.- Returns:
- new
Duration
with specified fields. - Throws:
java.lang.IllegalArgumentException
- if the arguments are out of range or have inconsistent sign.- Since:
- 0.5
-
fromMillis
public static Duration fromMillis(long millis)
Creates a newDuration
from given milliseconds.- Parameters:
millis
- the duration in milliseconds.- Returns:
- a new
Duration
from given milliseconds. - Throws:
java.lang.IllegalArgumentException
- if the number of milliseconds is out of the range that can be represented byDuration
.- Since:
- 0.5
-
toMillis
public long toMillis()
Converts aDuration
to milliseconds.- Returns:
- the milliseconds representation of this
Duration
. - Since:
- 0.13
-
getSeconds
public abstract long getSeconds()
Returns the number of seconds in theDuration
.- Returns:
- the number of seconds in the
Duration
. - Since:
- 0.5
-
getNanos
public abstract int getNanos()
Returns the number of nanoseconds in theDuration
.- Returns:
- the number of nanoseconds in the
Duration
. - Since:
- 0.5
-
compareTo
public int compareTo(Duration otherDuration)
Compares thisDuration
to the specifiedDuration
.- Specified by:
compareTo
in interfacejava.lang.Comparable<Duration>
- Parameters:
otherDuration
- the otherDuration
to compare to, notnull
.- Returns:
- the comparator value: zero if equal, negative if this duration is smaller than otherDuration, positive if larger.
- Throws:
java.lang.NullPointerException
- if otherDuration isnull
.
-
-