Immutable representation of a time span as defined in
the W3C XML Schema 1.0 specification.
A Duration object represents a period of Gregorian time,
which consists of six fields (years, months, days, hours,
minutes, and seconds) plus a sign (+/-) field.
The first five fields have non-negative (>=0) integers or null
(which represents that the field is not set),
and the seconds field has a non-negative decimal or null.
A negative sign indicates a negative duration.
This class provides a number of methods that make it easy
to use for the duration datatype of XML Schema 1.0 with
the errata.
Order relationship
Duration objects only have partial order, where two values A and B
maybe either:
- A<B (A is shorter than B)
- A>B (A is longer than B)
- A==B (A and B are of the same duration)
- A<>B (Comparison between A and B is indeterminate)
For example, 30 days cannot be meaningfully compared to one month.
The
Duration.compare(Duration duration) method implements this
relationship.
See the
Duration.isLongerThan(Duration) method for details about
the order relationship among Duration objects.
Operations over Duration
This class provides a set of basic arithmetic operations, such
as addition, subtraction and multiplication.
Because durations don't have total order, an operation could
fail for some combinations of operations. |