public final class Duration extends Object implements Comparable<Duration>, IEquatable<Duration>, IEquatableEpsilon<Duration>, ImmutableValueType
JulianDate
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(Duration timeSpan,
TimeStandard standard)

Duration(int days,
double seconds)
Initializes a new instance of
Duration from a specified number
of days and seconds. 
Duration(int days,
double seconds,
TimeStandard standard)
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. 
Duration(int days,
int hours,
int minutes,
double seconds,
TimeStandard standard)
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 
fromDays(double days,
TimeStandard standard)
Returns a
Duration that represents the specified number of days
using the specified time standard. 
static Duration 
fromHours(double hours)
Returns a
Duration that represents the specified number of hours. 
static Duration 
fromHours(double hours,
TimeStandard standard)
Returns a
Duration that represents the specified number of hours using the
specified time standard. 
static Duration 
fromMinutes(double minutes)
Returns a
Duration that represents the specified number of minutes. 
static Duration 
fromMinutes(double minutes,
TimeStandard standard)
Returns a
Duration that represents the specified number of minutes using the
specified time standard. 
static Duration 
fromSeconds(double seconds)
Returns a
Duration that represents the specified number of seconds. 
static Duration 
fromSeconds(double seconds,
TimeStandard standard)
Returns a
Duration that represents the specified number of seconds using the
specified time standard. 
int 
getDays()
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 
getSeconds()
Gets the seconds component of this
Duration . 
TimeStandard 
getStandard()
Gets the time standard in which this
Duration is measured. 
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 
toDuration()

String 
toString()

public Duration()
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
.ArgumentOutOfRangeException
 Thrown if the inputs represent a value too large to be stored in a Duration
.public Duration(int days, int hours, int minutes, double seconds, TimeStandard standard)
Duration
from a specified number
of days, hours, minutes, and seconds. It also specifies that the time is
measured using the specified time standard.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
.standard
 The time standard in which the time is measured.ArgumentOutOfRangeException
 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
.ArgumentOutOfRangeException
 Thrown if the inputs represent a value too large to be stored in a Duration
.public Duration(int days, double seconds, TimeStandard standard)
Duration
from a specified number
of days and seconds. It also specifies that the time is
measured using the specified time standard.days
 The number of days in the new Duration
.seconds
 The number of seconds in the new Duration
.standard
 The time standard in which the time is measured.ArgumentOutOfRangeException
 Thrown if the inputs represent a value too large to be stored in a Duration
.public Duration(@Nonnull Duration timeSpan)
Duration
from a Duration
.
The time standard is not specified, so this Duration
will match the
time standard of anything it is added to or subtracted from.timeSpan
 The time span.public Duration(@Nonnull Duration timeSpan, TimeStandard standard)
Duration
from a Duration
.
It also specifies that the time is measured using the specified
time standard.timeSpan
 The time span.standard
 The time standard in which the span is measured.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.@Nonnull public static Duration getMaxValue()
Duration
.
The value is Integer.MAX_VALUE
days and 86399.0 seconds.
@Nonnull public static Duration getMinValue()
Duration
.
The value is Integer.MIN_VALUE
days and 86399.0 seconds.
public final int getDays()
Duration
.public final double getSeconds()
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
.public final TimeStandard getStandard()
Duration
is measured.public final double getTotalDays()
Duration
.public final double getTotalSeconds()
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public final boolean equalsType(@Nonnull Duration other)
true
if this Duration
exactly equals another Duration
, within the limits
of floating point precision. To be considered equal, the Days
(get
)
and Standard
(get
) properties must be identical (or one must be null) and the
difference between the Seconds
(get
) properties must be less than 1.0e10.
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.
equalsType
in interface IEquatable<Duration>
other
 The other Duration
.true
if this Duration
exactly equals the other
Duration
, within the limits of floating point precision.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
)
and Standard
(get
) properties must be identical (or one must be null) and the
difference between the Seconds
(get
) properties must be less than 1.0e10.
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(@Nonnull Duration other, double epsilon)
true
if this Duration
is within epsilon
seconds of the
specified Duration
. That is, in order for the Durations
to be considered equal (and for
this function to return true
), the absolute value of the difference between them, in
seconds, must be less than or equal to epsilon
.equalsEpsilon
in interface IEquatableEpsilon<Duration>
other
 The Duration
to compare to this Duration
.epsilon
 The largest difference between the Durations
, in seconds, such that they will be considered equal.true
if the dates are equal as defined by the epsilon value.public final int compareTo(@Nonnull Duration other)
compareTo
in interface Comparable<Duration>
other
 An object to compare with this instance.Value  Meaning 

Less than zero 
This instance is less than other .

Zero 
This instance is equal to other .

Greater than zero 
This instance is greater than other .

ArgumentException
 Thrown when comparing this object to a Duration
defined in a different TimeStandard
.@Nonnull public final Duration add(@Nonnull 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 ArgumentException
.
other
 The Duration
to add to this instance.Duration
that represents the value of this instance plus the value of other
.ArgumentException
 Thrown if this Duration
and other
have different TimeStandards
.ArgumentOutOfRangeException
 Thrown if the result represents a value that cannot be be stored in a Duration
.@Nonnull public final Duration subtract(@Nonnull 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 ArgumentException
.
other
 The Duration
to subtract from this instance.Duration
that represents the value of this instance minus the value of other
.ArgumentException
 Thrown if this Duration
and other
have different TimeStandards
.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.public static boolean equals(@Nonnull Duration left, @Nonnull Duration right)
true
if two Durations
are exactly equal, within the limits
of floating point precision. To be considered equal, the Days
(get
)
and Standard
(get
) properties must be identical (or one must be null) and the
difference between the Seconds
(get
) properties must be less than 1.0e10.
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(@Nonnull Duration left, @Nonnull Duration right)
true
if two Durations
are NOT exactly equal, within the limits
of floating point precision. To be considered equal, the Days
(get
)
and Standard
(get
) properties must be identical (or one must be null) and the
difference between the Seconds
(get
) properties must be less than 1.0e10.
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(@Nonnull Duration left, @Nonnull Duration right)
true
if left
is shorter than right
.public static boolean greaterThan(@Nonnull Duration left, @Nonnull Duration right)
true
if left
is longer than right
.public static boolean lessThanOrEqual(@Nonnull Duration left, @Nonnull Duration right)
true
if left
is shorter than or exactly equal to right
.public static boolean greaterThanOrEqual(@Nonnull Duration left, @Nonnull Duration right)
true
if left
is longer than or exactly equal to right
.@Nonnull public static Duration add(@Nonnull Duration left, @Nonnull Duration right)
Duration
instances.@Nonnull public static Duration subtract(@Nonnull Duration left, @Nonnull Duration right)
left
 The subtrahend.right
 The minuend.left
minus right
.@Nonnull public static Duration negate(@Nonnull 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
.@Nonnull public static Duration multiply(@Nonnull Duration left, double right)
Duration
by a constant.public static double divide(@Nonnull Duration dividend, @Nonnull Duration divisor)
Duration
by another duration.@Nonnull public static Duration divide(@Nonnull Duration dividend, double divisor)
Duration
by a constant.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull public static Duration fromDays(double days, TimeStandard standard)
Duration
that represents the specified number of days
using the specified time standard.days
 The number of days to be represented by the returned Duration
.standard
 The time standard of the new Duration
.Duration
representing the specified number of days.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull public static Duration fromSeconds(double seconds, TimeStandard standard)
Duration
that represents the specified number of seconds using the
specified time standard.seconds
 The number of seconds to be represented by the returned Duration
.standard
 The time standard of the new Duration
.Duration
representing the specified number of seconds.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull public static Duration fromHours(double hours, TimeStandard standard)
Duration
that represents the specified number of hours using the
specified time standard.hours
 The number of hours to be represented by the returned Duration
.standard
 The time standard of the new Duration
.Duration
representing the specified number of hours.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull 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.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.@Nonnull public static Duration fromMinutes(double minutes, TimeStandard standard)
Duration
that represents the specified number of minutes using the
specified time standard.minutes
 The number of minutes to be represented by the returned Duration
.standard
 The time standard of the new Duration
.Duration
representing the specified number of minutes.ArgumentOutOfRangeException
 Thrown if the result represents a value too large to be stored in a Duration
.