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:
  • 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