public class TimeUnit extends SimpleUnit
This is a wrapper around ucar.units. The underlying ucar.units.Unit always has a value of "1.0", ie is a base unit.
kmUnit, meterUnit, pressureUnit
Constructor and Description |
---|
TimeUnit(double value,
java.lang.String unitString)
Constructor from a value and a unit name.
|
TimeUnit(java.lang.String text)
Constructor from a String.
|
TimeUnit(TimeUnit src)
Copy Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.util.Date |
add(java.util.Date d)
Add the time amount to the given Date, return a new Date.
|
double |
convertTo(double value,
TimeUnit outputUnit)
Convert given value of this unit to the new unit.
|
boolean |
equals(java.lang.Object o)
TimeUnits with same value and unitString are equal
|
double |
getFactor()
Get the factor that converts this unit to seconds.
|
java.lang.String |
getUnitString()
Get the "base" unit String, eg "secs" or "days"
|
double |
getValue()
Get the value.
|
double |
getValueInSeconds()
Get the time duration in seconds.
|
double |
getValueInSeconds(double value)
Get the time duration in seconds of the specified value.
|
int |
hashCode()
Override hashcode to be consistent with equals.
|
void |
setValue(double value)
Set the value in the original units.
|
void |
setValueInSeconds(double secs)
Set the value, using the given number of seconds.
|
java.lang.String |
toString()
String representation.
|
convertTo, factory, factoryWithExceptions, getCanonicalString, getConversionFactor, getImplementingClass, getUnit, isCompatible, isCompatible, isCompatibleWithExceptions, isDateUnit, isDateUnit, isTimeUnit, isTimeUnit, isUnknownUnit
public TimeUnit(double value, java.lang.String unitString) throws ucar.units.UnitException
value
- amount of the unit.unitString
- Time unit string from udunits.ucar.units.UnitException
- if parse failspublic TimeUnit(java.lang.String text) throws ucar.units.UnitException
text
- [value] ucar.units.UnitException
- is bad formatpublic TimeUnit(TimeUnit src)
src
- copy from herepublic java.util.Date add(java.util.Date d)
d
- add to this Datepublic double convertTo(double value, TimeUnit outputUnit) throws ucar.units.ConversionException
value
- in the units of this "base unit"outputUnit
- convert to this base type, must be convertible to units of "seconds"ucar.units.ConversionException
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public double getFactor()
public java.lang.String getUnitString()
getUnitString
in class SimpleUnit
public double getValue()
getValue
in class SimpleUnit
public double getValueInSeconds()
public double getValueInSeconds(double value)
value
- convert this value, must be in units of thispublic int hashCode()
hashCode
in class java.lang.Object
public void setValue(double value)
value
- set value, must be in units of thispublic void setValueInSeconds(double secs)
secs
- : number of seconds; convert this to the units of this TimeUnit.public java.lang.String toString()
toString
in class SimpleUnit