public final class Durations
extends java.lang.Object
protobuf/duration.proto. All operations throw an
IllegalArgumentException if the input(s) are not valid.| Modifier and Type | Field and Description |
|---|---|
private static java.util.Comparator<Duration> |
COMPARATOR |
(package private) static long |
DURATION_SECONDS_MAX |
(package private) static long |
DURATION_SECONDS_MIN |
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 | Constructor and Description |
|---|---|
private |
Durations() |
| 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 java.util.Comparator<Duration> |
comparator()
Returns a
Comparator for Durations which sorts in increasing chronological
order. |
static int |
compare(Duration x,
Duration y)
Compares two durations.
|
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. |
(package private) static Duration |
normalizedDuration(long seconds,
int nanos) |
static Duration |
parse(java.lang.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 java.lang.String |
toString(Duration duration)
Convert Duration to string format.
|
static final long DURATION_SECONDS_MIN
static final long DURATION_SECONDS_MAX
public static final Duration MIN_VALUE
Duration, approximately -10,000 years.public static final Duration MAX_VALUE
Duration, approximately +10,000 years.private static final java.util.Comparator<Duration> COMPARATOR
public static java.util.Comparator<Duration> comparator()
Comparator for Durations which sorts in increasing chronological
order. Nulls and invalid Durations are not allowed (see isValid(com.google.protobuf.Duration)).public static int compare(Duration x, Duration y)
Durations.comparator().compare(x, y).0 if x == y; a value less than 0 if x < y;
and a value greater than 0 if x > ypublic 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 java.lang.String toString(Duration duration)
java.lang.IllegalArgumentException - if the given duration is not in the valid range.public static Duration parse(java.lang.String value) throws java.text.ParseException
java.text.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)
public static Duration subtract(Duration d1, Duration d2)
static Duration normalizedDuration(long seconds, int nanos)