Package org.apache.groovy.dateutil

# Class BaseDuration

java.lang.Object
org.apache.groovy.dateutil.BaseDuration

All Implemented Interfaces:
  `Comparable<BaseDuration>`

Direct Known Subclasses:
  `DatumDependentDuration`, `Duration`

public abstract class BaseDuration extends Object implements Comparable<BaseDuration>
Base class for date and time durations (dequirked, `java.util.Date`-flavored).

This is the B1 prototype: the same value-class model as the legacy `groovy.time.BaseDuration`, but with the historical quirks removed:

- ago / from.now no longer zero the time-of-day for date-based durations — the behavior is now uniform across all durations (time is preserved), so a single implementation lives here rather than divergent overrides per subclass.
- `toMilliseconds()` is deterministic — datum-dependent amounts (years, months) use `ChronoUnit`'s estimated durations rather than resolving against `new Date()` ("now"), so the result no longer depends on when it is called.

See Also:
  - `Duration`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `BaseDuration.From`
  Helper for computing dates relative to the current time.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final int`
  `days`
  `protected final int`
  `hours`
  `protected final int`
  `millis`
  `protected final int`
  `minutes`
  `protected final int`
  `months`
  `protected final int`
  `seconds`
  `protected final int`
  `years`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `BaseDuration(int days, int hours, int minutes, int seconds, int millis)`
  `protected`
  `BaseDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `compareTo(BaseDuration other)`
  `Date`
  `getAgo()`
  The date this duration ago.
  `int`
  `getDays()`
  `BaseDuration.From`
  `getFrom()`
  Helper for computing dates relative to the current time.
  `int`
  `getHours()`
  `int`
  `getMillis()`
  `int`
  `getMinutes()`
  `int`
  `getMonths()`
  `int`
  `getSeconds()`
  `int`
  `getYears()`
  `Date`
  `plus(Date date)`
  Adds this duration to the supplied date.
  `long`
  `toMilliseconds()`
  Converts this duration to milliseconds.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### years

    protected final int years

  - ### months

    protected final int months

  - ### days

    protected final int days

  - ### hours

    protected final int hours

  - ### minutes

    protected final int minutes

  - ### seconds

    protected final int seconds

  - ### millis

    protected final int millis

- ## Constructor Details

  - ### BaseDuration

    protected BaseDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis)

  - ### BaseDuration

    protected BaseDuration(int days, int hours, int minutes, int seconds, int millis)

- ## Method Details

  - ### getYears

    public int getYears()

  - ### getMonths

    public int getMonths()

  - ### getDays

    public int getDays()

  - ### getHours

    public int getHours()

  - ### getMinutes

    public int getMinutes()

  - ### getSeconds

    public int getSeconds()

  - ### getMillis

    public int getMillis()

  - ### plus

    public Date plus(Date date)
    Adds this duration to the supplied date.

  - ### toMilliseconds

    public long toMilliseconds()
    Converts this duration to milliseconds.

    DEQUIRKED (B): deterministic. Years and months use `ChronoUnit` estimates (a year is exactly 12 estimated months, so `1.year == 12.months`); days and below are exact assuming 24-hour days. The result never depends on the current date.

  - ### getAgo

    public Date getAgo()
    The date this duration ago.

    DEQUIRKED (A): the time-of-day is preserved (no flooring to midnight), uniformly for all duration kinds.

  - ### getFrom

    public BaseDuration.From getFrom()
    Helper for computing dates relative to the current time. DEQUIRKED (A): time-of-day preserved.

  - ### compareTo

    public int compareTo(BaseDuration other)
    Specified by:
      `compareTo` in interface `Comparable<BaseDuration>`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`