Package groovy.time

Class BaseDuration

java.lang.Object
groovy.time.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.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Helper for computing dates relative to the current time.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    Day component.
    protected final int
    Hour component.
    protected final int
    Millisecond component.
    protected final int
    Minute component.
    protected final int
    Month component.
    protected final int
    Second component.
    protected final int
    Year component.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BaseDuration(int days, int hours, int minutes, int seconds, int millis)
    Creates a duration without year or month components.
    protected
    BaseDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis)
    Creates a duration with date and time components.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(BaseDuration otherDuration)
    Compares this duration with another by their millisecond values.
    abstract Date
    Returns the date represented by this duration ago.
    int
    Returns the day component.
    Returns a helper for computing dates relative to now.
    int
    Returns the hour component.
    int
    Returns the millisecond component.
    int
    Returns the minute component.
    int
    Returns the month component.
    int
    Returns the second component.
    int
    Returns the year component.
    plus(Date date)
    Adds this duration to the supplied date.
    abstract long
    Converts this duration to milliseconds.
    Returns a human-readable representation of this duration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • years

      protected final int years
      Year component.
    • months

      protected final int months
      Month component.
    • days

      protected final int days
      Day component.
    • hours

      protected final int hours
      Hour component.
    • minutes

      protected final int minutes
      Minute component.
    • seconds

      protected final int seconds
      Second component.
    • millis

      protected final int millis
      Millisecond component.
  • Constructor Details

    • BaseDuration

      protected BaseDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis)
      Creates a duration with date and time components.
      Parameters:
      years - the year component
      months - the month component
      days - the day component
      hours - the hour component
      minutes - the minute component
      seconds - the second component
      millis - the millisecond component
    • BaseDuration

      protected BaseDuration(int days, int hours, int minutes, int seconds, int millis)
      Creates a duration without year or month components.
      Parameters:
      days - the day component
      hours - the hour component
      minutes - the minute component
      seconds - the second component
      millis - the millisecond component
  • Method Details

    • getYears

      public int getYears()
      Returns the year component.
      Returns:
      the year component
    • getMonths

      public int getMonths()
      Returns the month component.
      Returns:
      the month component
    • getDays

      public int getDays()
      Returns the day component.
      Returns:
      the day component
    • getHours

      public int getHours()
      Returns the hour component.
      Returns:
      the hour component
    • getMinutes

      public int getMinutes()
      Returns the minute component.
      Returns:
      the minute component
    • getSeconds

      public int getSeconds()
      Returns the second component.
      Returns:
      the second component
    • getMillis

      public int getMillis()
      Returns the millisecond component.
      Returns:
      the millisecond component
    • plus

      public Date plus(Date date)
      Adds this duration to the supplied date.
      Parameters:
      date - the date to adjust
      Returns:
      the adjusted date
    • toString

      public String toString()
      Returns a human-readable representation of this duration.
      Overrides:
      toString in class Object
      Returns:
      the duration text
    • toMilliseconds

      public abstract long toMilliseconds()
      Converts this duration to milliseconds.
      Returns:
      the duration in milliseconds
    • getAgo

      public abstract Date getAgo()
      Returns the date represented by this duration ago.
      Returns:
      the computed date
    • getFrom

      public abstract BaseDuration.From getFrom()
      Returns a helper for computing dates relative to now.
      Returns:
      the relative-date helper
    • compareTo

      public int compareTo(BaseDuration otherDuration)
      Compares this duration with another by their millisecond values.
      Specified by:
      compareTo in interface Comparable<BaseDuration>
      Parameters:
      otherDuration - the duration to compare against
      Returns:
      a negative, zero, or positive value as this duration is less than, equal to, or greater than the other