public final class Duration extends Object implements Comparable<Duration>
This class offers the same precision as the JulianTime type. It stores a number of days as an int and a number of seconds as a
double.
| Constructor and Description |
|---|
Duration()
Initializes a new instance.
|
Duration(Duration timeSpan)
|
Duration(int days,
double seconds)
Initializes a new instance of
Duration from a specified number of days and seconds. |
Duration(int days,
int hours,
int minutes,
double seconds)
Initializes a new instance of
Duration from a specified number of days, hours, minutes, and seconds. |
| Modifier and Type | Method and Description |
|---|---|
Duration |
add(Duration other)
Adds the specified
Duration to this instance. |
static Duration |
add(Duration left,
Duration right)
Adds two specified
Duration instances. |
Duration |
addDays(double days)
|
Duration |
addSeconds(double seconds)
|
int |
compareTo(Duration other)
Compares this instance with another instance of the same type.
|
Duration |
divide(double constant)
Divides the
Duration by a constant. |
double |
divide(Duration divisor)
|
static Duration |
divide(Duration dividend,
double divisor)
Divides the
Duration by a constant. |
static double |
divide(Duration dividend,
Duration divisor)
Divides the
Duration by another Duration. |
static boolean |
equals(Duration left,
Duration right)
Returns
true if two Durations are exactly equal, within the limits of floating point precision. |
boolean |
equals(Object obj)
|
boolean |
equalsEpsilon(Duration other,
double epsilon)
|
boolean |
equalsType(Duration other)
|
static Duration |
fromDays(double days)
Returns a
Duration that represents the specified number of days. |
static Duration |
fromHours(double hours)
Returns a
Duration that represents the specified number of hours. |
static Duration |
fromMinutes(double minutes)
Returns a
Duration that represents the specified number of minutes. |
static Duration |
fromSeconds(double seconds)
Returns a
Duration that represents the specified number of seconds. |
int |
getDayCount()
Gets the day component of this
Duration. |
static Duration |
getMaxValue()
Gets the largest possible value of a
Duration. |
static Duration |
getMinValue()
Gets the smallest possible value of a
Duration. |
double |
getSecondsOfDay()
Gets the seconds component of this
Duration. |
double |
getTotalDays()
Gets the total number of whole and fractional days represented by this
Duration. |
double |
getTotalSeconds()
|
static Duration |
getZero()
Gets a
Duration of 0 days and seconds. |
static boolean |
greaterThan(Duration left,
Duration right)
Returns
true if left is longer than right. |
static boolean |
greaterThanOrEqual(Duration left,
Duration right)
Returns
true if left is longer than or exactly equal to right. |
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
static double |
hoursMinutesSecondsToSeconds(int hours,
int minutes,
double seconds)
Converts the specified number of hours, minutes, and seconds to total Duration in seconds.
|
static boolean |
lessThan(Duration left,
Duration right)
Returns
true if left is shorter than right. |
static boolean |
lessThanOrEqual(Duration left,
Duration right)
Returns
true if left is shorter than or exactly equal to right. |
Duration |
multiply(double constant)
Multiplies the
Duration by a constant. |
static Duration |
multiply(Duration left,
double right)
Multiplies the
Duration by a constant. |
static Duration |
negate(Duration value)
Inverts a specified
Duration. |
static boolean |
notEquals(Duration left,
Duration right)
Returns
true if two Durations are NOT exactly equal, within the limits of floating point precision. |
Duration |
subtract(Duration other)
Subtracts the specified
Duration from this instance. |
static Duration |
subtract(Duration left,
Duration right)
|
Duration |
toJavaDuration()
|
String |
toString()
|
public Duration()
getZero().public Duration(int days,
int hours,
int minutes,
double seconds)
Duration from a specified number of days, hours, minutes, and seconds. The time standard is not
specified, so this Duration will match the time standard of anything it is added to or subtracted from.days - The number of days in the new Duration.hours - The number of hours in the new Duration.minutes - The number of minutes in the new Duration.seconds - The number of seconds in the new Duration.IllegalArgumentException - Thrown if the inputs represent a value too large to be stored in a Duration.public Duration(int days,
double seconds)
Duration from a specified number of days and seconds. The time standard is not specified, so this Duration will match the time standard of anything it is added to or subtracted from.days - The number of days in the new Duration.seconds - The number of seconds in the new Duration.IllegalArgumentException - Thrown if the inputs represent a value too large to be stored in a Duration.public static double hoursMinutesSecondsToSeconds(int hours,
int minutes,
double seconds)
hours - The number of hours.minutes - The number of minutes.seconds - The number of seconds.@NotNull public static Duration getMaxValue()
Duration.
The value is Integer.MAX_VALUE days and 86399.0 seconds.
@NotNull public static Duration getMinValue()
Duration.
The value is Integer.MIN_VALUE days and -86399.0 seconds.
@NotNull public static Duration getZero()
Duration of 0 days and seconds.public final int getDayCount()
Duration.public final double getSecondsOfDay()
Duration. This is the number of seconds represented by this Duration in addition to the
Days (get), so it will always be less than TimeConstants.SecondsPerDay.getDayCount().public final double getTotalDays()
Duration.public final double getTotalSeconds()
Duration, including the seconds that compose the days returned by the Days
(get) property.@NotNull public final Duration toJavaDuration()
public int hashCode()
public final boolean equalsType(@NotNull
Duration other)
true if this Duration exactly equals another Duration, within the limits of floating point precision. To be
considered equal, the Days (get) properties must be identical and the difference between the Seconds
(get) properties must be less than 1.0e-10.
This method returns false if the two instances have different time standards, even if the values would be the same when converted to
the same time standard.
public boolean equals(Object obj)
true if this Duration exactly equals another Duration, within the limits of floating point precision. To be
considered equal, the Days (get) properties must be identical (or one must be null) and the difference between the
Seconds (get) properties must be less than 1.0e-10.
This method returns false if the two instances have different time standards, even if the values would be the same when converted to
the same time standard.
public final boolean equalsEpsilon(@NotNull
Duration other,
double epsilon)
public final int compareTo(@NotNull
Duration other)
compareTo in interface Comparable<Duration>other - An object to compare with this instance.Comparable.compareTo(Object)@NotNull public final Duration add(@NotNull Duration other)
Duration to this instance.
The two Durations must have the same time standard, or one of the time standards must be null. Attempting to add two Duration instances with different time standards will result in an IllegalArgumentException.
@NotNull public final Duration subtract(@NotNull Duration other)
Duration from this instance.
The two Durations must have the same time standard, or one of the time standards must be null. Attempting to add two Duration instances with different time standards will result in an IllegalArgumentException.
@NotNull public final Duration multiply(double constant)
Duration by a constant.constant - The constant by which to multiply the Duration.Duration that represents the value of this instance multiplied by the constant.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.public final double divide(@NotNull
Duration divisor)
@NotNull public final Duration divide(double constant)
Duration by a constant.constant - The constant by which to divide the Duration.Duration that represents the value of this instance divided by the constant.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.@NotNull public final Duration addSeconds(double seconds)
seconds - The number of seconds to add.Duration which is the sum of the original Duration and the specified number of seconds.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.@NotNull public final Duration addDays(double days)
days - The number of days to add.Duration which is the sum of the original Duration and the specified number of days.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.public static boolean equals(@NotNull
Duration left,
@NotNull
Duration right)
true if two Durations are exactly equal, within the limits of floating point precision. To be considered
equal, the Days (get) properties must be identical (or one must be null) and the difference between the Seconds (get) properties must be less than 1.0e-10.
This method returns false if the two instances have different time standards, even if the values would be the same when converted to
the same time standard.
public static boolean notEquals(@NotNull
Duration left,
@NotNull
Duration right)
true if two Durations are NOT exactly equal, within the limits of floating point precision. To be considered
equal, the Days (get) properties must be identical (or one must be null) and the difference between the Seconds (get) properties must be less than 1.0e-10.
This method returns false if the two instances have different time standards, even if the values would be the same when converted to
the same time standard.
public static boolean lessThan(@NotNull
Duration left,
@NotNull
Duration right)
true if left is shorter than right.public static boolean greaterThan(@NotNull
Duration left,
@NotNull
Duration right)
true if left is longer than right.public static boolean lessThanOrEqual(@NotNull
Duration left,
@NotNull
Duration right)
true if left is shorter than or exactly equal to right.public static boolean greaterThanOrEqual(@NotNull
Duration left,
@NotNull
Duration right)
true if left is longer than or exactly equal to right.@NotNull public static Duration add(@NotNull Duration left, @NotNull Duration right)
Duration instances.@NotNull public static Duration subtract(@NotNull Duration left, @NotNull Duration right)
left - The subtrahend.right - The minuend.left minus right.@NotNull public static Duration negate(@NotNull Duration value)
Duration. For example, if the value represents a positive quantity of time, the returned Duration
will be a negative quantity of time.value - The value to invert.Duration.@NotNull public static Duration multiply(@NotNull Duration left, double right)
Duration by a constant.public static double divide(@NotNull
Duration dividend,
@NotNull
Duration divisor)
Duration by another Duration.@NotNull public static Duration divide(@NotNull Duration dividend, double divisor)
Duration by a constant.@NotNull public static Duration fromDays(double days)
Duration that represents the specified number of days.days - The number of days to be represented by the returned Duration.Duration representing the specified number of days.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.@NotNull public static Duration fromSeconds(double seconds)
Duration that represents the specified number of seconds.seconds - The number of seconds to be represented by the returned Duration.Duration representing the specified number of seconds.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.@NotNull public static Duration fromHours(double hours)
Duration that represents the specified number of hours.hours - The number of hours to be represented by the returned Duration.Duration representing the specified number of hours.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.@NotNull public static Duration fromMinutes(double minutes)
Duration that represents the specified number of minutes.minutes - The number of minutes to be represented by the returned Duration.Duration representing the specified number of minutes.IllegalArgumentException - Thrown if the result represents a value too large to be stored in a Duration.