public final class Durations extends Object
protobuf/duration.proto
. All operations throw an
IllegalArgumentException
if the input(s) are not valid.Modifier and Type | Field and Description |
---|---|
static Duration |
MAX_VALUE
A constant holding the maximum valid
Duration , approximately +10,000 years. |
static Duration |
MIN_VALUE
A constant holding the minimum valid
Duration , approximately -10,000 years. |
Modifier and Type | Method and Description |
---|---|
static Duration |
add(Duration d1,
Duration d2)
Add two durations.
|
static Duration |
checkValid(Duration duration)
Throws an
IllegalArgumentException if the given Duration is not valid. |
static Comparator<Duration> |
comparator()
Returns a
Comparator for Duration s which sorts in increasing chronological
order. |
static Duration |
fromMicros(long microseconds)
Create a Duration from the number of microseconds.
|
static Duration |
fromMillis(long milliseconds)
Create a Duration from the number of milliseconds.
|
static Duration |
fromNanos(long nanoseconds)
Create a Duration from the number of nanoseconds.
|
static Duration |
fromSeconds(long seconds)
Create a Duration from the number of seconds.
|
static boolean |
isValid(Duration duration)
Returns true if the given
Duration is valid. |
static boolean |
isValid(long seconds,
int nanos)
Returns true if the given number of seconds and nanos is a valid
Duration . |
static Duration |
parse(String value)
Parse from a string to produce a duration.
|
static Duration |
subtract(Duration d1,
Duration d2)
Subtract a duration from another.
|
static long |
toMicros(Duration duration)
Convert a Duration to the number of microseconds.
|
static long |
toMillis(Duration duration)
Convert a Duration to the number of milliseconds.
|
static long |
toNanos(Duration duration)
Convert a Duration to the number of nanoseconds.
|
static long |
toSeconds(Duration duration)
Convert a Duration to the number of seconds.
|
static String |
toString(Duration duration)
Convert Duration to string format.
|
public static final Duration MIN_VALUE
Duration
, approximately -10,000
years.public static Comparator<Duration> comparator()
Comparator
for Duration
s which sorts in increasing chronological
order. Nulls and invalid Duration
s are not allowed (see isValid(com.google.protobuf.Duration)
).public static boolean isValid(Duration duration)
Duration
is valid. The seconds
value must be in the
range [-315,576,000,000, +315,576,000,000]. The nanos
value must be in the range
[-999,999,999, +999,999,999].
Note: 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.
public static boolean isValid(long seconds, int nanos)
Duration
. The seconds
value must be in the range [-315,576,000,000, +315,576,000,000]. The nanos
value must be in the range [-999,999,999, +999,999,999].
Note: 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.
public static Duration checkValid(Duration duration)
IllegalArgumentException
if the given Duration
is not valid.public static String toString(Duration duration)
IllegalArgumentException
- if the given duration is not in the valid range.public static Duration parse(String value) throws ParseException
ParseException
- if parsing fails.public static Duration fromSeconds(long seconds)
public static long toSeconds(Duration duration)
public static Duration fromMillis(long milliseconds)
public static long toMillis(Duration duration)
public static Duration fromMicros(long microseconds)
public static long toMicros(Duration duration)
public static Duration fromNanos(long nanoseconds)
public static long toNanos(Duration duration)
Copyright © 2008–2017. All rights reserved.