Extensions to Duration

The class de.fhg.fokus.xtensions.datetime.DurationExtensions provides static extension method for the JDK class java.time.Duration

Since Java does not allow operator overloading, the Duration class provides many methods with names corresponding to operators, like plus, minus, dividedBy, multipliedBy, and negated. Since Xtend does allow operator overloading for the corresponding operators, aliases for the operators +, -, /, *, and unary - are defined.

The Duration class also provides static factory methods for durations of a given time units (e.g. Duration ofNanos(long nanos)).
To make these constructions more easy to read, the DurationExtensions class provides extension methods to the long type.

Example:

import static extension de.fhg.fokus.xtensions.datetime.DurationExtensions.*
import java.time.Duration
// ...
val Duration twoPointFiveSeconds = 2.seconds + 500.milliseconds
Tip

Related JavaDocs:

results matching ""

    No results matching ""