Package thredds.client.catalog
Class TimeDuration
- java.lang.Object
-
- thredds.client.catalog.TimeDuration
-
@Immutable public class TimeDuration extends Object
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:- a valid udunits string compatible with "secs"
- an xsd:duration type specified in the following form "PnYnMnDTnHnMnS" where:
- P indicates the period (required)
- nY indicates the number of years
- nM indicates the number of months
- nD indicates the number of days
- T indicates the start of a time section (required if you are going to specify hours, minutes, or seconds)
- nH indicates the number of hours
- nM indicates the number of minutes
- nS indicates the number of seconds
- See Also:
- "https://www.unidata.ucar.edu/projects/THREDDS/tech/catalog/InvCatalogSpec.html#durationType"
-
-
Constructor Summary
Constructors Constructor Description TimeDuration(TimeUnit timeUnit)
Construct from a TimeUnit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
String
getText()
Get the textTimeUnit
getTimeUnit()
Get the time unitdouble
getValue()
Get the duration in natural units, ie units of getTimeUnit()double
getValue(String unit)
Get the time duration in a specified unit of time.double
getValue(TimeUnit want)
Get the time duration in a specified unit of time.double
getValueInSeconds()
Get the duration in secondsint
hashCode()
boolean
isBlank()
If this is a blank stringstatic TimeDuration
parse(String text)
Construct from 1) udunit time unit string, 2) xsd:duration syntax, 3) blank string.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.CalendarPeriod
toCalendarPeriod()
String
toString()
-
-
-
Constructor Detail
-
TimeDuration
public TimeDuration(TimeUnit timeUnit)
Construct from a TimeUnit.
-
-
Method Detail
-
parse
public static TimeDuration parse(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.
-
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()
-
getValue
public double getValue(TimeUnit want)
Get the time duration in a specified unit of time.- Parameters:
want
- in these units- Returns:
- the duration in units
- Throws:
IllegalArgumentException
- if specified unit is not compatible with time
-
getValue
public double getValue(String unit)
Get the time duration in a specified unit of time.- Parameters:
unit
- unit spec from new TimeUnit(String)- Returns:
- the duration in units
- Throws:
IllegalArgumentException
- if specified unit is not compatible with time
-
toCalendarPeriod
public CalendarPeriod toCalendarPeriod()
-
getValueInSeconds
public double getValueInSeconds()
Get the duration in seconds
-
isBlank
public boolean isBlank()
If this is a blank string
-
getTimeUnit
public TimeUnit getTimeUnit()
Get the time unit
-
getText
public String getText()
Get the text
-
-