Package io.opencensus.common
Class Duration
java.lang.Object
io.opencensus.common.Duration
- All Implemented Interfaces:
Comparable<Duration>
- Direct Known Subclasses:
AutoValue_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 -
Method Summary
Modifier and TypeMethodDescriptionint
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
Returns the number of seconds in theDuration
.long
toMillis()
Converts aDuration
to milliseconds.
-
Constructor Details
-
Duration
Duration()
-
-
Method Details
-
create
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:
IllegalArgumentException
- if the arguments are out of range or have inconsistent sign.- Since:
- 0.5
-
fromMillis
Creates a newDuration
from given milliseconds.- Parameters:
millis
- the duration in milliseconds.- Returns:
- a new
Duration
from given milliseconds. - Throws:
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
Compares thisDuration
to the specifiedDuration
.- Specified by:
compareTo
in interfaceComparable<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:
NullPointerException
- if otherDuration isnull
.
-