public class IlvLinearTimeConverter extends Object implements IlvTimeConverter
IlvLinearTimeConverter is capable of converting
a Date to a double value, and a
double value to a Date in a linear way.
The converter is defined by a reference time and a unit duration. The reference time represents the time where the double value is 0, and the unit duration is the duration of a double value of 1.
Here is the conversion formula:
double value = ( time value - reference time ) / unit duration
It is strongly recommended that the reference time should be evenly divisible by the
unit duration. In other words, getReferenceTime().getTime() % getUnitDuration().getMillis() = 0.
This ensures the highest level of precision during the conversion calculations.
DEFAULT_REFERENCE_TIME| Constructor and Description |
|---|
IlvLinearTimeConverter()
Creates an
IlvLinearTimeConverter with a default
unit duration of one hour. |
IlvLinearTimeConverter(Date refTime,
IlvDuration unit)
Creates a linear time converter.
|
| Modifier and Type | Method and Description |
|---|---|
Date |
getReferenceTime()
Returns the reference time.
|
Date |
getTime(double units)
Converts a double value to a
Date. |
IlvDuration |
getUnitDuration()
Returns the unit duration.
|
double |
getUnits(Date time)
Converts a
Date to a double. |
boolean |
isLinear()
Returns whether the time converter is continuous and linear.
|
void |
setReferenceTime(Date time)
Sets the reference time.
|
void |
setUnitDuration(IlvDuration unit)
Sets the unit duration.
|
String |
toString()
Returns a string representation of this converter.
|
public IlvLinearTimeConverter(Date refTime, IlvDuration unit)
refTime - Gives the reference time for the new converter.
It is strongly recommended that the reference time should be evenly
divisible by the unit duration. In other words,
refTime.getTime() % unit.getMillis() = 0.unit - Defines the unit time used for the conversion. The value
provided should not be 0.public IlvLinearTimeConverter()
IlvLinearTimeConverter with a default
unit duration of one hour.public Date getReferenceTime()
setReferenceTime(java.util.Date)public void setReferenceTime(Date time)
time - The new reference time
It is strongly recommended that the reference time should be evenly
divisible by the unit duration. In other words,
time.getTime() % getUnitDuration().getMillis() = 0.getReferenceTime()public IlvDuration getUnitDuration()
public void setUnitDuration(IlvDuration unit)
unit - The new unit duration.
It is strongly recommended that the reference time should be evenly
divisible by the unit duration. In other words,
getReferenceTime().getTime() % unit.getMillis() = 0.
The value provided must not be 0.getUnitDuration()public double getUnits(Date time)
Date to a double.getUnits in interface IlvTimeConvertertime - The Date to be converted.public Date getTime(double units)
Date.getTime in interface IlvTimeConverterunits - The double value to be converted.public boolean isLinear()
true.isLinear in interface IlvTimeConverter© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.