public class IlvDuration extends Object implements Serializable, Comparable
IlvDuration
represents an absolute time period, with millisecond
precision. As such, instances of this class cannot be used to represent logical
concepts that are timezone or locale dependent, such as one day or one month. For
logical calendar computations that are timezone and locale aware, you must use methods
of the java.util.Calendar
class and the IlvCalendarUtil
utility
class. For example, to advance a Date
by one logical day in the current
default timezone and locale, you would use:
Calendar cal = Calendar.getInstance(); cal.setTime(aDate); cal.add(Calendar.DAY_OF_YEAR, 1); Date nextDay = cal.getTime();
IlvDuration
is an immutable class with value semantics.Modifier and Type | Field and Description |
---|---|
static IlvDuration |
ONE_DAY
A duration of 1 day that is 24 hours long.
|
static long |
ONE_DAY_MILLIS
The number of milliseconds in 1 day.
|
static IlvDuration |
ONE_HOUR
A duration of 1 hour.
|
static long |
ONE_HOUR_MILLIS
The number of milliseconds in 1 hour.
|
static IlvDuration |
ONE_MINUTE
A duration of 1 minute.
|
static long |
ONE_MINUTE_MILLIS
The number of milliseconds in 1 minute.
|
static IlvDuration |
ONE_SECOND
A duration of 1 second.
|
static long |
ONE_SECOND_MILLIS
The number of milliseconds in 1 second.
|
static IlvDuration |
ONE_WEEK
A duration of 1 week, assuming 7 days of 24 hours each.
|
static long |
ONE_WEEK_MILLIS
The number of milliseconds in 1 week.
|
Constructor and Description |
---|
IlvDuration(long millis)
Creates an
IlvDuration that represents the specified number of
milliseconds. |
Modifier and Type | Method and Description |
---|---|
Date |
add(Date t)
Returns a new
Date that is the sum of the specified time and this
duration. |
IlvDuration |
add(IlvDuration delta)
Returns a new
IlvDuration that is the sum of this duration and the
specified duration. |
int |
compareTo(IlvDuration anotherDuration)
Returns the result of comparing this duration to the specified duration.
|
int |
compareTo(Object o)
Returns the result of comparing this duration to another object.
|
IlvDuration |
divide(double divisor)
Returns a new
IlvDuration that is the result of dividing this duration
by the specified amount. |
IlvDuration |
divide(int divisor)
Returns a new
IlvDuration that is the result of dividing this duration
by the specified amount. |
boolean |
equals(Object obj)
Returns whether an object is logically equal to this duration.
|
long |
getMillis()
Returns the number of milliseconds that this duration represents.
|
int |
hashCode()
Returns a hashcode for this duration.
|
IlvDuration |
multiply(double multiplier)
Returns a new
IlvDuration that is the result of multiplying this
duration by the specified amount. |
IlvDuration |
multiply(int multiplier)
Returns a new
IlvDuration that is the result of multiplying this
duration by the specified amount. |
IlvDuration |
subtract(IlvDuration delta)
Returns a new
IlvDuration that is the difference between this duration
and the specified duration. |
String |
toString()
Returns a string representation of this duration.
|
public static final long ONE_SECOND_MILLIS
public static final long ONE_MINUTE_MILLIS
public static final long ONE_HOUR_MILLIS
public static final long ONE_DAY_MILLIS
ONE_DAY
,
Constant Field Valuespublic static final long ONE_WEEK_MILLIS
ONE_WEEK
,
Constant Field Valuespublic static final IlvDuration ONE_SECOND
public static final IlvDuration ONE_MINUTE
public static final IlvDuration ONE_HOUR
public static final IlvDuration ONE_DAY
ONE_DAY_MILLIS
public static final IlvDuration ONE_WEEK
ONE_WEEK_MILLIS
public IlvDuration(long millis)
IlvDuration
that represents the specified number of
milliseconds.millis
- The number of milliseconds.public long getMillis()
public Date add(Date t)
Date
that is the sum of the specified time and this
duration. Note that this method does not take account of Daylight Saving Time
transitions or other timezone and locale dependencies. For logical calendar
computations you should use methods of the java.util.Calendar
class and
the IlvCalendarUtil
utility class. For example, to advance a
Date
by one logical day in the current default timezone and locale, you
would use:
Calendar cal = Calendar.getInstance(); cal.setTime(aDate); cal.add(Calendar.DAY_OF_YEAR, 1); Date nextDay = cal.getTime();
t
- The time to add to this duration.public IlvDuration add(IlvDuration delta)
IlvDuration
that is the sum of this duration and the
specified duration.delta
- The duration to add to this duration.public IlvDuration subtract(IlvDuration delta)
IlvDuration
that is the difference between this duration
and the specified duration.delta
- The duration to subtract from this duration.public IlvDuration multiply(int multiplier)
IlvDuration
that is the result of multiplying this
duration by the specified amount.multiplier
- The amount to multiply this duration by.public IlvDuration multiply(double multiplier)
IlvDuration
that is the result of multiplying this
duration by the specified amount.multiplier
- The amount to multiply this duration by.public IlvDuration divide(int divisor)
IlvDuration
that is the result of dividing this duration
by the specified amount.divisor
- The amount to divide this duration by.public IlvDuration divide(double divisor)
IlvDuration
that is the result of dividing this duration
by the specified amount.divisor
- The amount to divide this duration by.public boolean equals(Object obj)
true
if and only if the argument is an IlvDuration
object
that represents the same length of time as this duration.public int compareTo(IlvDuration anotherDuration)
anotherDuration
- The duration to be compared to this one.public int compareTo(Object o)
IlvDuration
, this function behaves like compareTo(IlvDuration)
.
Otherwise, it throws a ClassCastException
because
IlvDuration
objects are comparable only to other
IlvDuration
objects.compareTo
in interface Comparable
o
- The object to be compared.ClassCastException
- if the argument is not an IlvDuration
.public int hashCode()
long
value returned by the getMillis()
method. That is, the hash code is the value of the expression:
(int)(this.getMillis()^(this.getMillis() >>> 32))
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.