public class AbsoluteTime extends HighResolutionTime<AbsoluteTime>
Chronograph
. For the universal clock, the
fixed point is the Epoch (January 1, 1970, 00:00:00 GMT).
The correctness of the Epoch as a time base depends on the
realtime clock synchronization with an external world time reference.
This representation was designed to be compatible with
the standard Java representation of an absolute time in the
java.util.Date
class.
A time object in normalized form represents negative time when
both components are nonzero and negative, or one is nonzero and
negative and the other is zero. For add
and subtract
negative values behave as they do in arithmetic.
Caution: This class is explicitly unsafe for multithreading when being changed. Code that mutates instances of this class should synchronize at a higher level.
Constructor and Description |
---|
AbsoluteTime()
Equivalent to
AbsoluteTime(long, int, Chronograph) with the
argument list (0, 0, null) . |
AbsoluteTime(AbsoluteTime time)
Equivalent to
AbsoluteTime(long, int, Chronograph) with the
argument list (time.getMilliseconds(), time.getNanoseconds(), time.getChronograph()) . |
AbsoluteTime(AbsoluteTime time,
Chronograph chronograph)
Equivalent to
AbsoluteTime(long, int, Chronograph) with
arguments time.getMilliseconds(), time.getNanoseconds(), chronograph() . |
AbsoluteTime(AbsoluteTime time,
Clock clock)
Deprecated.
since version 2.0
|
AbsoluteTime(Chronograph chronograph)
Equivalent to
AbsoluteTime(long, int, Chronograph) with the
argument list (0, 0, chronograph) . |
AbsoluteTime(Clock clock)
Deprecated.
since version 2.0
|
AbsoluteTime(java.util.Date date)
Equivalent to
AbsoluteTime(long, int, Chronograph) with the
argument list (date.getTime(), 0, null) . |
AbsoluteTime(java.util.Date date,
Chronograph chronograph)
Equivalent to
AbsoluteTime(long, int, Chronograph) with the
argument list (date.getTime(), 0, chronograph) . |
AbsoluteTime(java.util.Date date,
Clock clock)
Deprecated.
since version 2.0
|
AbsoluteTime(long millis,
int nanos)
Equivalent to
AbsoluteTime(long, int, Chronograph) with the
argument list (millis, nanos, null) |
AbsoluteTime(long millis,
int nanos,
Chronograph chronograph)
Constructs an
AbsoluteTime object with time millisecond
and nanosecond components past the epoch for Chronograph . |
AbsoluteTime(long millis,
int nanos,
Clock clock)
Deprecated.
since version 2.0
|
Modifier and Type | Method and Description |
---|---|
AbsoluteTime |
absolute(Chronograph chronograph)
Creates a copy of
this modified when necessary to have the
specified chronograph association. |
AbsoluteTime |
absolute(Chronograph chronograph,
AbsoluteTime dest)
Copies
this into dest , when necessary modified to
have the specified chronograph association. |
AbsoluteTime |
absolute(Clock clock)
Deprecated.
since version 2.0
|
AbsoluteTime |
absolute(Clock clock,
AbsoluteTime dest)
Deprecated.
since version 2.0
|
AbsoluteTime |
add(long millis,
int nanos)
Creates a new object representing the result of adding
millis and nanos to the values from this
and normalizing the result. |
AbsoluteTime |
add(long millis,
int nanos,
AbsoluteTime dest)
Returns an object containing the value resulting from adding
millis and nanos to the values from this and
normalizing the result. |
AbsoluteTime |
add(RelativeTime time)
Creates a new instance of
AbsoluteTime representing the
result of adding time to the value of this and
normalizing the result. |
AbsoluteTime |
add(RelativeTime time,
AbsoluteTime dest)
Returns an object containing the value resulting from adding
time to the value of this and normalizing the result. |
java.util.Date |
getDate()
Converts the time given by
this to a Date format. |
RelativeTime |
relative(Chronograph chronograph)
Converts the time of
this to a relative time, using the
given instance of Chronograph to determine the current
time. |
RelativeTime |
relative(Chronograph chronograph,
RelativeTime dest)
Converts the time of
this to a relative time, using the
given instance of Chronograph to determine the current
time. |
RelativeTime |
relative(Clock clock)
Deprecated.
since version 2.0
|
RelativeTime |
relative(Clock clock,
RelativeTime dest)
Deprecated.
since version 2.0
|
AbsoluteTime |
set(java.util.Date date)
Changes the time represented by
this to that given by the
parameter. |
RelativeTime |
subtract(AbsoluteTime time)
Creates a new instance of
RelativeTime representing the
result of subtracting time from the value of this
and normalizing the result. |
RelativeTime |
subtract(AbsoluteTime time,
RelativeTime dest)
Returns an object containing the value resulting from subtracting
time from the value of this and normalizing the
result. |
AbsoluteTime |
subtract(RelativeTime time)
Creates a new instance of
AbsoluteTime representing the
result of subtracting time from the value of this
and normalizing the result. |
AbsoluteTime |
subtract(RelativeTime time,
AbsoluteTime dest)
Returns an object containing the value resulting from subtracting
time from the value of this and normalizing the
result. |
java.lang.String |
toString()
Creates a printable string of the time given by
this . |
clone, compareTo, equals, equals, getChronograph, getClock, getMilliseconds, getNanoseconds, hashCode, set, set, set, set, waitForObject
public AbsoluteTime(long millis, int nanos, Chronograph chronograph) throws StaticIllegalArgumentException
AbsoluteTime
object with time millisecond
and nanosecond components past the epoch for Chronograph
.
The value of the AbsoluteTime
instance is based on the
parameter millis
plus the parameter nanos
. The
construction is subject to millis
and nanos
parameters normalization. When, after normalization, the time
object is negative, the time represented by this is time before
this
chronograph's epoch
. The chronograph
association is made with the Chronograph
parameter. When
Chronograph
is null
the association is made with
the default realtime clock.
Note that the start of a chronograph's epoch is an attribute of the chronograph. It is defined as the Epoch (00:00:00 GMT on Jan 1, 1970) for the calendar clock, but other classes of chronograph may define other epochs.
millis
- The desired value for the millisecond component of
this
. The actual value is the result of parameter
normalization.nanos
- The desired value for the nanosecond component of
this
. The actual value is the result of parameter
normalization.chronograph
- Provides the time reference for the
newly constructed object. The realtime clock is used when
this argument is null
.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component when normalizing.public AbsoluteTime(long millis, int nanos) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
with the
argument list (millis, nanos, null)
millis
- The desired value for the millisecond component
of this
. The actual value is the result
of parameter normalization.nanos
- The desired value for the nanosecond component
of this
.
The actual value is the result of parameter normalization.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component when normalizing.public AbsoluteTime(java.util.Date date, Chronograph chronograph) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
with the
argument list (date.getTime(), 0, chronograph)
.
Warning: While the date
is used to set the milliseconds
component of the new AbsoluteTime
object (with nanoseconds
component set to 0), the new object represents the date
only when the Chronograph
parameter has an epoch
equal to
Epoch.
The time reference is given by the Chronograph
parameter. When Chronograph
is null
the
association is made with the default realtime clock.
date
- The java.util.Date
representation of the time
past the epoch
.chronograph
- Provides the time reference for
the newly constructed object.StaticIllegalArgumentException
- when the date
parameter is null
.public AbsoluteTime(java.util.Date date) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
with the
argument list (date.getTime(), 0, null)
.date
- The java.util.Date
representation of the time
past the epoch
.StaticIllegalArgumentException
- when the date
parameter is null
.public AbsoluteTime(AbsoluteTime time) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
with the
argument list (time.getMilliseconds(), time.getNanoseconds(), time.getChronograph())
.time
- The AbsoluteTime
object which is the source for
the copy.StaticIllegalArgumentException
- when the time
parameter is null
.public AbsoluteTime(Chronograph chronograph)
AbsoluteTime(long, int, Chronograph)
with the
argument list (0, 0, chronograph)
.chronograph
- Provides the time reference for the newly
constructed object.public AbsoluteTime()
AbsoluteTime(long, int, Chronograph)
with the
argument list (0, 0, null)
.@Deprecated public AbsoluteTime(long millis, int nanos, Clock clock) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
millis
- The desired value for the millisecond component
of this
.
The actual value is the result of parameter normalization.nanos
- The desired value for the nanosecond component
of this
.
The actual value is the result of parameter normalization.clock
- The clock providing the association for the newly
constructed object.StaticIllegalArgumentException
- when there is an overflow in the
millisecond component when normalizing.@Deprecated public AbsoluteTime(AbsoluteTime time, Clock clock) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
with the
arguments time.getMilliseconds(), time.getNanoseconds(), clock()
.time
- The AbsoluteTime
object which is the
source for the copy.clock
- The clock providing the association for the newly
constructed object.StaticIllegalArgumentException
- when the time
parameter is null
.public AbsoluteTime(AbsoluteTime time, Chronograph chronograph) throws StaticIllegalArgumentException
AbsoluteTime(long, int, Chronograph)
with
arguments time.getMilliseconds(), time.getNanoseconds(), chronograph()
.time
- The AbsoluteTime
object which is the
source for the copy.chronograph
- The chronograph providing the association for the newly
constructed object.StaticIllegalArgumentException
- when the time
parameter is null
.@Deprecated public AbsoluteTime(java.util.Date date, Clock clock) throws StaticIllegalArgumentException
AbsoluteTime(Date, Chronograph)
date
- The java.util.Date
representation of the time
past the Epoch.clock
- The clock providing the association for the newly
constructed object.StaticIllegalArgumentException
- when the date
parameter is null
.@Deprecated public AbsoluteTime(Clock clock)
AbsoluteTime(Chronograph)
clock
- The clock providing the association for the newly
constructed object.public AbsoluteTime absolute(Chronograph chronograph)
this
modified when necessary to have the
specified chronograph association. A new object is allocated for
the result. This method is the implementation of the
abstract
method of the HighResolutionTime
base
class. No conversion into AbsoluteTime
is needed in this
case. The result is associated with the Chronograph
passed
as a parameter. When Chronograph
is null
, the
association is made with the default realtime clock.absolute
in class HighResolutionTime<AbsoluteTime>
chronograph
- It is used only
as the new time reference associated with the result, since
no conversion is needed.this
in a newly allocated
AbsoluteTime
object, associated with the
Chronograph
parameter.public AbsoluteTime absolute(Chronograph chronograph, AbsoluteTime dest)
this
into dest
, when necessary modified to
have the specified chronograph association. A new object is
allocated for the result. This method is the implementation of the
abstract
method of the HighResolutionTime
base
class. No conversion into AbsoluteTime
is needed in this
case. The result is associated with the Chronograph
passed
as a parameter. When Chronograph
is null
, the
association is made with the default realtime clock.absolute
in class HighResolutionTime<AbsoluteTime>
chronograph
- It is used only as the new time reference
associated with the result, since no conversion is needed.dest
- the instance to fill.this
in a newly allocated
AbsoluteTime
object, associated with the
Chronograph
parameter.public RelativeTime relative(Chronograph chronograph)
this
to a relative time, using the
given instance of Chronograph
to determine the current
time. The calculation is the current time indicated by the given
instance of Chronograph
subtracted from the time given by
this
. When Chronograph
is null
, the default
realtime clock is assumed. A destination object is allocated to
return the result. The time reference of the result is given by the
Chronograph
passed as a parameter.relative
in class HighResolutionTime<AbsoluteTime>
chronograph
- The instance of Chronograph
used to
convert the time of this
into relative time, and
the new chronograph association for the result.RelativeTime
conversion in a newly allocated
object, associated with the Chronograph
parameter.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public RelativeTime relative(Chronograph chronograph, RelativeTime dest)
this
to a relative time, using the
given instance of Chronograph
to determine the current
time. The calculation is the current time indicated by the given
instance of Chronograph
subtracted from the time given by
this
. When Chronograph
is null
, the default
realtime clock is assumed. When dest
is not null
,
the result is placed in it and returned. Otherwise, a new object is
allocated for the result. The time reference of the result is
given by the Chronograph
passed as a parameter.relative
in class HighResolutionTime<AbsoluteTime>
chronograph
- The instance of Chronograph
used to
convert the time of this
into relative time, and
the new chronograph association for the result.dest
- When dest
is not null
, the result is
placed in it and returned.RelativeTime
conversion in dest
when
dest
is not null
,
otherwise the result is returned in a newly allocated object,
associated with the Chronograph
parameter.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime add(long millis, int nanos) throws java.lang.ArithmeticException
millis
and nanos
to the values from this
and normalizing the result. The result will have the same chronograph
association as this
.millis
- The number of milliseconds to be added to this
.nanos
- The number of nanoseconds to be added to this
.AbsoluteTime
object whose time is the
normalization of this
plus millis
and
nanos
.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime add(long millis, int nanos, AbsoluteTime dest) throws java.lang.ArithmeticException
millis
and nanos
to the values from this
and
normalizing the result. When dest
is not null
, the
result is placed in it and returned. Otherwise, a new object is
allocated for the result. The result will have the same chronograph
association as this
, and the chronograph association with
dest
is ignored.millis
- The number of milliseconds to be added to this
.nanos
- The number of nanoseconds to be added to this
.dest
- When dest
is not null
, the result is
placed in it and returned.this
plus
millis
and nanos
in dest
when
dest
is not null
, otherwise the result is
returned in a newly allocated object.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime add(RelativeTime time) throws java.lang.ArithmeticException, StaticIllegalArgumentException
AbsoluteTime
representing the
result of adding time
to the value of this
and
normalizing the result. The Chronograph
associated with
this
and the Chronograph
associated with the time
parameter must be the same, and such association is used for the
result.time
- The time to add to this
.AbsoluteTime
object whose time is the
normalization of this
plus the parameter time
.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the Chronograph
associated with the time
parameter are different,
or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime add(RelativeTime time, AbsoluteTime dest) throws java.lang.ArithmeticException, StaticIllegalArgumentException
time
to the value of this
and normalizing the result.
When dest
is not null
, the result is placed in it
and returned. Otherwise, a new object is allocated for the result.
The Chronograph
associated with this
and the
Chronograph
associated with the time
parameter must be
the same, and such association is used for the result. The
Chronograph
associated with the dest
parameter is ignored.time
- The time to add to this
.dest
- When dest
is not null
, the result is
placed in it and returned.this
plus the
RelativeTime
parameter time
in
dest
when dest
is not null
,
otherwise the result is returned in a newly allocated object.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the Chronograph
associated with the time
parameter are
different, or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public java.util.Date getDate() throws StaticUnsupportedOperationException
this
to a Date
format.
Note that Date
represents time as milliseconds so the
nanoseconds of this
will be lost.Date
object with a value of the
time past the Epoch represented by this
.StaticUnsupportedOperationException
- when the Chronograph
associated with this
does not have
the concept of date.public AbsoluteTime set(java.util.Date date) throws StaticIllegalArgumentException
this
to that given by the
parameter. Note that Date
represents time as milliseconds
so the nanoseconds of this
will be set to 0. The chronograph
association is implicitly made with the default realtime clock.date
- A reference to a Date
which will become the
time represented by this
after the completion of
this method.this
StaticIllegalArgumentException
- when the parameter
date
is null
.public RelativeTime subtract(AbsoluteTime time) throws StaticIllegalArgumentException, java.lang.ArithmeticException
RelativeTime
representing the
result of subtracting time
from the value of this
and normalizing the result. The Chronograph
associated with
this
and the Chronograph
associated with the time
parameter must be the same, and such association is used for the
result.time
- The time to subtract from this
.RelativeTime
object whose time is
the normalization of this
minus the
AbsoluteTime
parameter time
.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the Chronograph
associated with the time
parameter are different,
or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit
in the normalized format.public RelativeTime subtract(AbsoluteTime time, RelativeTime dest) throws StaticIllegalArgumentException, java.lang.ArithmeticException
time
from the value of this
and normalizing the
result. When dest
is not null
, the result is
placed there and returned. Otherwise, a new object is allocated for
the result. The Chronograph
associated with this
and the
Chronograph
associated with the time
parameter must be
the same, and such association is used for the result. The
Chronograph
associated with the dest
parameter is ignored.time
- The time to subtract from this
.dest
- When dest
is not null
, the result is
placed in it and returned.this
minus the
AbsoluteTime
parameter time
in dest
when dest
is not null
, otherwise the result
is returned in a newly allocated object.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the Chronograph
associated with the time
parameter are different,
or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime subtract(RelativeTime time) throws StaticIllegalArgumentException, java.lang.ArithmeticException
AbsoluteTime
representing the
result of subtracting time
from the value of this
and normalizing the result. The Chronograph
associated with
this
and the Chronograph
associated with the time
parameter must be the same, and such association is used for the
result.time
- The time to subtract from this
.AbsoluteTime
object whose time is the
normalization of this
minus the parameter
time
.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the Chronograph
associated with the time
parameter are different,
or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public AbsoluteTime subtract(RelativeTime time, AbsoluteTime dest) throws StaticIllegalArgumentException, java.lang.ArithmeticException
time
from the value of this
and normalizing the
result. When dest
is not null
, the result is
placed there and returned. Otherwise, a new object is allocated for
the result. The Chronograph
associated with this
and the
Chronograph
associated with the time
parameter must be
the same, and such association is used for the result. The
Chronograph
associated with the dest
parameter is ignored.time
- The time to subtract from this
.dest
- When dest
is not null
, the result is
placed there and returned.this
minus the
RelativeTime
parameter time
in dest
when dest
is not null
, otherwise the result
is returned in a newly allocated object.StaticIllegalArgumentException
- when the Chronograph
associated with this
and the Chronograph
associated with the time
parameter are different,
or when the time
parameter is null
.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.public java.lang.String toString()
this
.
The string shall be a decimal representation of the milliseconds and nanosecond values; formatted as follows "(2251 ms, 750000 ns)"
toString
in class java.lang.Object
this
.@Deprecated public AbsoluteTime absolute(Clock clock)
absolute(Chronograph)
.absolute
in class HighResolutionTime<AbsoluteTime>
clock
- The clock
parameter is
used only as the new clock association with the result,
since no conversion is needed.this
in a
newly allocated AbsoluteTime
object,
associated with the clock
parameter.@Deprecated public AbsoluteTime absolute(Clock clock, AbsoluteTime dest)
absolute(Chronograph, AbsoluteTime)
.absolute
in class HighResolutionTime<AbsoluteTime>
clock
- The clock
parameter is used only as the new
clock association with the result, since no conversion is
needed.dest
- When dest
is not null
, the result is
placed in it and returned.this
in dest
when dest
is not null
, otherwise the result is returned in a
newly allocated object. It is associated with the clock
parameter.@Deprecated public RelativeTime relative(Clock clock) throws java.lang.ArithmeticException
relative(Chronograph)
.relative
in class HighResolutionTime<AbsoluteTime>
clock
- The instance of Clock
used to convert the time
of this
into relative time, and the new clock
association for the result.RelativeTime
conversion in a newly allocated
object, associated with the clock
parameter.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.@Deprecated public RelativeTime relative(Clock clock, RelativeTime dest) throws java.lang.ArithmeticException
relative(Chronograph, RelativeTime)
.relative
in class HighResolutionTime<AbsoluteTime>
clock
- The instance of Clock
used to convert the time
of this
into relative time, and the new clock
association for the result.dest
- When dest
is not null
, the result is
placed in it and returned.RelativeTime
conversion in dest
when
dest
is not null
, otherwise the result is
returned in a newly allocated object. It is associated
with the clock
parameter.java.lang.ArithmeticException
- when the result does not fit in the
normalized format.