ucar.nc2.units
Class DateUnit

java.lang.Object
  extended by ucar.nc2.units.SimpleUnit
      extended by ucar.nc2.units.DateUnit
Direct Known Subclasses:
JavaDateUnit

public class DateUnit
extends SimpleUnit

Handles udunits dates, represented as "n units of time since reference date" eg "1203 days since 1970-01-01 00:00:00".

This is a wrapper around ucar.units package. It tracks the value, the base time unit, and the date origin seperately.

Version:
$Revision:63 $ $Date:2006-07-12 21:50:51Z $
Author:
caron

Field Summary
 
Fields inherited from class ucar.nc2.units.SimpleUnit
dateUnit, debugParse, format, secsUnit, uu
 
Constructor Summary
DateUnit(java.lang.String text)
          Constructor.
 
Method Summary
 java.util.Date getDate()
          Get the equivilent java.util.Date.
 java.util.Date getDateOrigin()
          Get the origin Date.
static java.util.Date getStandardDate(java.lang.String text)
          Create a java.util.Date from this udunits String.
static java.util.Date getStandardOrISO(java.lang.String text)
          Create a java.util.Date from a udunit or ISO String.
 TimeUnit getTimeUnit()
          For udunit dates, get the time unit.
 java.lang.String getTimeUnitString()
          For udunit dates, get the time unit only, as a String, eg "secs" or "days"
 java.lang.String getUnitsString()
          The udunits string, but no value, ie its a base unit.
 java.util.Date makeDate(double val)
          Create a Date from this base unit and the given value.
 java.lang.String makeStandardDateString(double value)
          Make a standard GMT string representation from this unit and given value.
 double makeValue(java.util.Date date)
          Create the equivilent value from this base unit and the given Date.
 java.lang.String toString()
          Unit string representation.
 
Methods inherited from class ucar.nc2.units.SimpleUnit
convertTo, factory, factoryWithExceptions, getConversionFactor, getUnit, getUnitString, getValue, isCompatible, isCompatible, isCompatibleWithExceptions, isDateUnit, isDateUnit, isTimeUnit, isTimeUnit, isUnknownUnit, makeUnit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateUnit

public DateUnit(java.lang.String text)
         throws java.lang.Exception
Constructor.

Parameters:
text - udunits String, eg 3 secs since 1991-01-01T03:12
Throws:
java.lang.Exception - if malformed String.
Method Detail

getStandardDate

public static java.util.Date getStandardDate(java.lang.String text)
Create a java.util.Date from this udunits String.

Parameters:
text - a udunit string.
[number] (units) since [-]Y[Y[Y[Y]]]-MM-DD[(T| )hh[:mm[:ss[.sss*]]][ [+|-]hh[[:]mm]]]
Returns:
Date or null if not date unit.

getStandardOrISO

public static java.util.Date getStandardOrISO(java.lang.String text)
Create a java.util.Date from a udunit or ISO String.

Parameters:
text - a udunit or ISO string.
Returns:
Date or null if not date unit.
See Also:
getStandardDate(java.lang.String), DateFormatter.getISODate(java.lang.String)

getDateOrigin

public java.util.Date getDateOrigin()
Get the origin Date.

Returns:
Date or null if not a time unit.

getTimeUnitString

public java.lang.String getTimeUnitString()
For udunit dates, get the time unit only, as a String, eg "secs" or "days"


getTimeUnit

public TimeUnit getTimeUnit()
For udunit dates, get the time unit.


getDate

public java.util.Date getDate()
Get the equivilent java.util.Date.

Returns:
Date or null if failure

makeDate

public java.util.Date makeDate(double val)
Create a Date from this base unit and the given value.

Parameters:
val - value in the units of this base unit, eg sec since base date
Returns:
Date .

makeValue

public double makeValue(java.util.Date date)
Create the equivilent value from this base unit and the given Date. Inverse of makeDate.

Parameters:
date - to convert.
Returns:
value in units of this base unit.

makeStandardDateString

public java.lang.String makeStandardDateString(double value)
Make a standard GMT string representation from this unit and given value.

Parameters:
value - of time in these units.
Returns:
String or null if not time unit.

toString

public java.lang.String toString()
Description copied from class: SimpleUnit
Unit string representation.

Overrides:
toString in class SimpleUnit

getUnitsString

public java.lang.String getUnitsString()
The udunits string, but no value, ie its a base unit.