This class provides a representation of durations and a parser for
strings that represent durations.
Strings that can be parsed consist of value/unit pairs. Values can
be arbitrary text, valid unit names are "years", "yrs", "months",
"mts", "hours", "hrs", "min" and "sec". There may be only one pair
for each unit i.e. "5 years 3 yrs" is illegal.
Value/unit pairs must be separated from each other with at least
one whitespace character. Units may follow values immediately if
the value is a number, else they must be separated by at least one
whitespace.
Any duration unit may be omitted, but the descending order of units
must be preserved.
Parsing is done in two phases. First, during parse the
value/unit pairs are identified and the values are stored as
strings. This allows the class even to be used when the values are
expressions that must be evaluated. If this feature is used, the
evaluation must be performed by retrieving the string values (using
"...AsParsed "), evaluating the expression and setting
the result.
Duration will try to convert the parsed string to a
number only if a unit is accessed and has not been set
explicitly. Thus, all accessor methods may throw a
NumberFormatException even if parse has
not thrown a ParseException .
author: Michael Lipp version: $Revision: 1.3 $ |