Package: org.apache.groovy.dateutil

## [Java] Class BaseDuration

- org.apache.groovy.dateutil.BaseDuration

- All Implemented Interfaces and Traits:
    Comparable

      public abstract class BaseDuration
      extends Object
      implements Comparable

  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
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `BaseDuration.From` | Helper for computing dates relative to the current time.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected int` | `days` |
    `protected int` | `hours` |
    `protected int` | `millis` |
    `protected int` | `minutes` |
    `protected int` | `months` |
    `protected int` | `seconds` |
    `protected int` | `years` |

  - ### Constructor Summary

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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### 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 Detail

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

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

  - ### Method Detail

    - #### public int compareTo(BaseDuration other)

    - #### 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.

    - #### public int getDays()

    - #### public BaseDuration.From getFrom()

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

    - #### public int getHours()

    - #### public int getMillis()

    - #### public int getMinutes()

    - #### public int getMonths()

    - #### public int getSeconds()

    - #### public int getYears()

    - #### public Date plus(Date date)

      Adds this duration to the supplied date.

    - #### 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.

    - #### public String toString()