Class Duration

java.lang.Object
org.apache.groovy.dateutil.BaseDuration
org.apache.groovy.dateutil.Duration
All Implemented Interfaces:
Comparable<BaseDuration>
Direct Known Subclasses:
TimeDuration

public class Duration extends BaseDuration
A context-independent duration: days and below, whose length is known without a datum.

DEQUIRKED: toMilliseconds(), getAgo() and getFrom() are now inherited from BaseDuration (uniform, deterministic, time-preserving); only the type-preserving arithmetic remains here.

  • Constructor Details

    • Duration

      public Duration(int days, int hours, int minutes, int seconds, int millis)
      Stores the day and time components. Years and months stay zero.
      Parameters:
      days - whole days
      hours - hours
      minutes - minutes
      seconds - seconds
      millis - milliseconds
  • Method Details

    • plus

      public Duration plus(Duration rhs)
      Adds each day and time component of rhs. The components are not normalized.
      Parameters:
      rhs - duration to add
      Returns:
      the component-wise sum
    • plus

      public Duration plus(TimeDuration rhs)
      Adds this duration to rhs by calling rhs.plus(this), so the result is a TimeDuration.
      Parameters:
      rhs - duration to add
      Returns:
      the sum, typed as rhs computes it
    • plus

      Adds this duration to rhs by calling rhs.plus(this). Years and months stay those of rhs; the day and time components are added.
      Parameters:
      rhs - duration to add
      Returns:
      the sum, typed as rhs computes it
    • minus

      public Duration minus(Duration rhs)
      Subtracts each day and time component of rhs. The components are not normalized.
      Parameters:
      rhs - duration to subtract
      Returns:
      the component-wise difference
    • minus

      public TimeDuration minus(TimeDuration rhs)
      Subtracts each day and time component of rhs and returns a TimeDuration. The components are not normalized.
      Parameters:
      rhs - duration to subtract
      Returns:
      the component-wise difference
    • minus

      Subtracts rhs. Years and months of rhs are negated, and the day and time components are subtracted. The result is a DatumDependentDuration.
      Parameters:
      rhs - duration to subtract
      Returns:
      the component-wise difference
    • minus

      Subtracts rhs. Years and months of rhs are negated, and the day and time components are subtracted. The result is a TimeDatumDependentDuration.
      Parameters:
      rhs - duration to subtract
      Returns:
      the component-wise difference