Package: groovy.time

## [Java] Class Duration

- groovy.time.Duration

-     @Deprecated
      public class Duration
      extends BaseDuration

  Duration represents time periods which have values independent of the context. So, whilst we can't say how long a month is without knowing the year and the name of the month, we know how long a day is independent of the date.

  This is not 100% true for days. Days can actually be 23, 24 or 25 hours long (due to daylight saving adjustments.)

  If you ask Duration to convert itself to milliseconds then it will work on the basis of 24 hours in a day. If you add or subtract it from a date it will take daylight saving into account.

  deprecated:
    Superseded by `org.apache.groovy.dateutil.Duration` (the dequirked `java.util.Date` flavor) or `java.time.Duration`/`java.time.Period`. This legacy class is retained, unchanged, for backward compatibility.

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class BaseDuration` | `days, hours, millis, minutes, months, seconds, years`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `Duration(int days, int hours, int minutes, int seconds, int millis)` Creates a fixed duration.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Date` | `getAgo()` Returns the date represented by this duration ago.
    `` | `public From` | `getFrom()` Returns a helper for computing dates relative to now.
    `` | `public Duration` | `minus(Duration rhs)` Subtracts another fixed duration.
    `` | `public TimeDuration` | `minus(TimeDuration rhs)` Subtracts a time duration.
    `` | `public DatumDependentDuration` | `minus(DatumDependentDuration rhs)` Subtracts a datum-dependent duration.
    `` | `public TimeDatumDependentDuration` | `minus(TimeDatumDependentDuration rhs)` Subtracts a mixed time and datum-dependent duration.
    `` | `public Duration` | `plus(Duration rhs)` Adds another fixed duration.
    `` | `public Duration` | `plus(TimeDuration rhs)` Adds a time duration.
    `` | `public DatumDependentDuration` | `plus(DatumDependentDuration rhs)` Adds a datum-dependent duration.
    `` | `public long` | `toMilliseconds()` Converts this duration to milliseconds assuming 24-hour days.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class BaseDuration` | `compareTo, getAgo, getDays, getFrom, getHours, getMillis, getMinutes, getMonths, getSeconds, getYears, plus, toMilliseconds, toString`

- - ### Constructor Detail

    - #### public Duration(int days, int hours, int minutes, int seconds, int millis)

      Creates a fixed duration.

      Parameters:
        `days` - the day component
        `hours` - the hour component
        `minutes` - the minute component
        `seconds` - the second component
        `millis` - the millisecond component

  - ### Method Detail

    - #### public Date getAgo()

      Returns the date represented by this duration ago.

      Returns:
        the computed date

    - #### public From getFrom()

      Returns a helper for computing dates relative to now.

      Returns:
        the relative-date helper

    - #### public Duration minus(Duration rhs)

      Subtracts another fixed duration.

      Parameters:
        `rhs` - the duration to subtract
      Returns:
        the resulting duration

    - #### public TimeDuration minus(TimeDuration rhs)

      Subtracts a time duration.

      Parameters:
        `rhs` - the duration to subtract
      Returns:
        the resulting duration

    - #### public DatumDependentDuration minus(DatumDependentDuration rhs)

      Subtracts a datum-dependent duration.

      Parameters:
        `rhs` - the duration to subtract
      Returns:
        the resulting duration

    - #### public TimeDatumDependentDuration minus(TimeDatumDependentDuration rhs)

      Subtracts a mixed time and datum-dependent duration.

      Parameters:
        `rhs` - the duration to subtract
      Returns:
        the resulting duration

    - #### public Duration plus(Duration rhs)

      Adds another fixed duration.

      Parameters:
        `rhs` - the duration to add
      Returns:
        the combined duration

    - #### public Duration plus(TimeDuration rhs)

      Adds a time duration.

      Parameters:
        `rhs` - the duration to add
      Returns:
        the combined duration

    - #### public DatumDependentDuration plus(DatumDependentDuration rhs)

      Adds a datum-dependent duration.

      Parameters:
        `rhs` - the duration to add
      Returns:
        the combined duration

    - #### public long toMilliseconds()

      Converts this duration to milliseconds assuming 24-hour days.

      Returns:
        the duration in milliseconds