Static Public Member Functions | |
static Duration | add (Duration d1, Duration d2) |
static Duration | checkNotNegative (Duration duration) |
static Duration | checkPositive (Duration duration) |
static Duration | checkValid (Duration duration) |
static Duration | checkValid (Duration.Builder durationBuilder) |
static Comparator< Duration > | comparator () |
static int | compare (Duration x, Duration y) |
static Duration | fromDays (long days) |
static Duration | fromHours (long hours) |
static Duration | fromMicros (long microseconds) |
static Duration | fromMillis (long milliseconds) |
static Duration | fromMinutes (long minutes) |
static Duration | fromNanos (long nanoseconds) |
static Duration | fromSeconds (long seconds) |
static boolean | isNegative (Duration duration) |
static boolean | isValid (Duration duration) |
static boolean | isValid (long seconds, int nanos) |
static Duration | parse (String value) throws ParseException |
static Duration | subtract (Duration d1, Duration d2) |
static long | toDays (Duration duration) |
static long | toHours (Duration duration) |
static long | toMicros (Duration duration) |
static long | toMillis (Duration duration) |
static long | toMinutes (Duration duration) |
static long | toNanos (Duration duration) |
static long | toSeconds (Duration duration) |
static double | toSecondsAsDouble (Duration duration) |
static String | toString (Duration duration) |
Static Public Attributes | |
static final Duration | MAX_VALUE |
static final Duration | MIN_VALUE |
static final Duration | ZERO = Duration.newBuilder().setSeconds(0L).setNanos(0).build() |
Private Member Functions | |
Durations () | |
Static Private Attributes | |
static final Comparator< Duration > | COMPARATOR |
static final long | SECONDS_PER_DAY = SECONDS_PER_HOUR * 24 |
static final long | SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60 |
static final long | SECONDS_PER_MINUTE = 60L |
Utilities to help create/manipulate
. All operations throw an IllegalArgumentException if the input(s) are not {@linkplain isValid(Duration) valid}.
Definition at line 54 of file Durations.java.
|
inlineprivate |
Definition at line 73 of file Durations.java.
Add two durations.
Definition at line 423 of file Durations.java.
|
inlinestatic |
Ensures that the given Duration is not negative.
IllegalArgumentException | if duration
|
NullPointerException | if duration
null
|
Definition at line 156 of file Durations.java.
Ensures that the given Duration is positive.
IllegalArgumentException | if duration
|
NullPointerException | if duration
null
|
Definition at line 169 of file Durations.java.
Throws an IllegalArgumentException if the given Duration is not valid.
Definition at line 180 of file Durations.java.
|
inlinestatic |
Builds the given builder and throws an IllegalArgumentException if it is not valid. See checkValid(Duration).
Definition at line 201 of file Durations.java.
|
inlinestatic |
Returns a Comparator for Durations which sorts in increasing chronological order. Nulls and invalid Durations are not allowed (see isValid).
Definition at line 90 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of days.
Definition at line 278 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of hours.
Definition at line 287 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of microseconds.
Definition at line 319 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of milliseconds.
Definition at line 311 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of minutes.
Definition at line 296 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of nanoseconds.
Definition at line 327 of file Durations.java.
|
inlinestatic |
Create a Duration from the number of seconds.
Definition at line 305 of file Durations.java.
|
inlinestatic |
Returns whether the given Duration is negative or not.
Definition at line 144 of file Durations.java.
|
inlinestatic |
Returns true if the given Duration is valid. The
value must be in the range [-315,576,000,000, +315,576,000,000]. The
value must be in the range [-999,999,999, +999,999,999].
Note: Durations less than one second are represented with a 0
field and a positive or negative
field. For durations of one second or more, a non-zero value for the
field must be of the same sign as the
field.
Definition at line 114 of file Durations.java.
|
inlinestatic |
Returns true if the given number of seconds and nanos is a valid Duration. The
value must be in the range [-315,576,000,000, +315,576,000,000]. The
value must be in the range [-999,999,999, +999,999,999].
Note: Durations less than one second are represented with a 0
field and a positive or negative
field. For durations of one second or more, a non-zero value for the
field must be of the same sign as the
field.
Definition at line 128 of file Durations.java.
|
inlinestatic |
Parse from a string to produce a duration.
ParseException | if parsing fails. |
Definition at line 241 of file Durations.java.
|
inlinestatic |
Subtract a duration from another.
Definition at line 431 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of days. The result will be rounded towards 0 to the nearest day.
Definition at line 339 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of hours. The result will be rounded towards 0 to the nearest hour.
Definition at line 348 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of microseconds. The result will be rounded towards 0 to the nearest microseconds. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.
Definition at line 405 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of milliseconds. The result will be rounded towards 0 to the nearest millisecond. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.
Definition at line 393 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of minutes. The result will be rounded towards 0 to the nearest minute.
Definition at line 357 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of nanoseconds.
Definition at line 414 of file Durations.java.
|
inlinestatic |
Convert a Duration to the number of seconds. The result will be rounded towards 0 to the nearest second. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.
Definition at line 366 of file Durations.java.
|
inlinestatic |
Returns the number of seconds of the given duration as a
. This method should be used to accommodate APIs that only accept durations as
values.
This conversion may lose precision.
If you need the number of seconds in this duration as a
(not a
), simply use
or toSeconds (which includes validation).
Definition at line 383 of file Durations.java.
|
inlinestatic |
Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits depending on the precision required to represent the exact Duration value. For example: "1s", "1.010s", "1.000000100s", "-3.100s" The range that can be represented by Duration is from -315,576,000,000 to +315,576,000,000 inclusive (in seconds).
IllegalArgumentException | if the given duration is not in the valid range. |
Definition at line 214 of file Durations.java.
|
staticprivate |
Definition at line 75 of file Durations.java.
|
static |
A constant holding the maximum valid Duration, approximately
years.
Definition at line 67 of file Durations.java.
|
static |
A constant holding the minimum valid Duration, approximately
years.
Definition at line 63 of file Durations.java.
|
staticprivate |
Definition at line 60 of file Durations.java.
|
staticprivate |
Definition at line 59 of file Durations.java.
|
staticprivate |
Definition at line 58 of file Durations.java.
|
static |
A constant holding the duration of zero.
Definition at line 71 of file Durations.java.