ucar.nc2.units
Class TimeDuration

java.lang.Object
  extended by ucar.nc2.units.TimeDuration

public class TimeDuration
extends Object

Implements the thredds "duration" XML element type: specifies a length of time. This is really the same as a ucar.nc2.units.TimeUnit, but it allows xsd:duration syntax as well as udunits syntax. It also keeps track if the text is empty.

A duration can be one of the following:

  1. a valid udunits string compatible with "secs"
  2. an xsd:duration type specified in the following form "PnYnMnDTnHnMnS" where:

Author:
john caron
See Also:
"http://www.unidata.ucar.edu/projects/THREDDS/tech/catalog/InvCatalogSpec.html#durationType"

Constructor Summary
TimeDuration(String text)
          Construct from 1) udunit time unit string, 2) xsd:duration syntax, 3) blank string.
TimeDuration(TimeDuration src)
          Copy constructor.
TimeDuration(TimeUnit timeUnit)
          Construct from a TimeUnit.
 
Method Summary
 boolean equals(Object o)
          TimeDurations with same value in seconds are equals
 String getText()
          Get the String text
 TimeUnit getTimeUnit()
          Get the corresponding time unit
 double getValue()
          Get the duration in natural units, ie units of getTimeUnit()
 double getValue(TimeUnit want)
          Get the time duration in a specified unit of time.
 double getValueInSeconds()
          Get the duration in seconds
 int hashCode()
          Override to be consistent with equals
 boolean isBlank()
          If this is a blank string
static void main(String[] args)
           
static TimeDuration parseW3CDuration(String text)
          A time span as defined in the W3C XML Schema 1.0 specification: "PnYnMnDTnHnMnS, where nY represents the number of years, nM the number of months, nD the number of days, 'T' is the date/time separator, nH the number of hours, nM the number of minutes and nS the number of seconds.
 void setValueInSeconds(double secs)
          Set the duration in seconds
 String toString()
          String representation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeDuration

public TimeDuration(TimeDuration src)
Copy constructor.

Parameters:
src - copy this

TimeDuration

public TimeDuration(TimeUnit timeUnit)
Construct from a TimeUnit.

Parameters:
timeUnit - copy this

TimeDuration

public TimeDuration(String text)
             throws ParseException
Construct from 1) udunit time unit string, 2) xsd:duration syntax, 3) blank string.

Parameters:
text - parse this text.
Throws:
ParseException - if invalid text.
Method Detail

parseW3CDuration

public static TimeDuration parseW3CDuration(String text)
                                     throws ParseException
A time span as defined in the W3C XML Schema 1.0 specification: "PnYnMnDTnHnMnS, where nY represents the number of years, nM the number of months, nD the number of days, 'T' is the date/time separator, nH the number of hours, nM the number of minutes and nS the number of seconds. The number of seconds can include decimal digits to arbitrary precision."

Parameters:
text - parse this text, format PnYnMnDTnHnMnS
Returns:
TimeDuration
Throws:
ParseException - when text is misformed

getValue

public double getValue()
Get the duration in natural units, ie units of getTimeUnit()

Returns:
the duration in natural units

getValue

public double getValue(TimeUnit want)
                throws ConversionException
Get the time duration in a specified unit of time.

Parameters:
want - in these units
Returns:
the duration in units
Throws:
ConversionException - is specified unit is not compatible with time

getValueInSeconds

public double getValueInSeconds()
Get the duration in seconds

Returns:
the duration in seconds

setValueInSeconds

public void setValueInSeconds(double secs)
Set the duration in seconds

Parameters:
secs - the duration in seconds

isBlank

public boolean isBlank()
If this is a blank string

Returns:
true if this is a blank string

getTimeUnit

public TimeUnit getTimeUnit()
Get the corresponding time unit

Returns:
the corresponding time unit

getText

public String getText()
Get the String text

Returns:
the text

toString

public String toString()
String representation

Overrides:
toString in class Object
Returns:
getText()

hashCode

public int hashCode()
Override to be consistent with equals

Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
TimeDurations with same value in seconds are equals

Overrides:
equals in class Object

main

public static void main(String[] args)


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.