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:
new Date() ("now"), so the result no longer depends on when it is called.| Modifiers | Name | Description |
|---|---|---|
static class |
BaseDuration.From |
Helper for computing dates relative to the current time. |
| Modifiers | Name | Description |
|---|---|---|
protected int |
days |
Whole days stored in this duration. |
protected int |
hours |
Hours stored in this duration. |
protected int |
millis |
Milliseconds stored in this duration. |
protected int |
minutes |
Minutes stored in this duration. |
protected int |
months |
Whole months stored in this duration. |
protected int |
seconds |
Seconds stored in this duration. |
protected int |
years |
Whole years stored in this duration. |
| Constructor and description |
|---|
protected BaseDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis)Stores every calendar and time component of the duration. |
protected BaseDuration(int days, int hours, int minutes, int seconds, int millis)Stores the day and time components. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public int |
compareTo(BaseDuration other)Orders durations by toMilliseconds(), so years and months use the ChronoUnit estimates and the shorter units are exact. |
|
public Date |
getAgo()The date this duration ago. |
|
public int |
getDays()Returns the stored day count. |
|
public BaseDuration.From |
getFrom()Helper for computing dates relative to the current time. |
|
public int |
getHours()Returns the stored hour count. |
|
public int |
getMillis()Returns the stored millisecond count. |
|
public int |
getMinutes()Returns the stored minute count. |
|
public int |
getMonths()Returns the stored month count. |
|
public int |
getSeconds()Returns the stored second count. |
|
public int |
getYears()Returns the stored year count. |
|
public Date |
plus(Date date)Adds this duration to the supplied date. |
|
public long |
toMilliseconds()Converts this duration to milliseconds. |
|
public String |
toString()Lists each non-zero component. |
Whole days stored in this duration.
Hours stored in this duration.
Milliseconds stored in this duration.
Minutes stored in this duration.
Whole months stored in this duration.
Seconds stored in this duration.
Whole years stored in this duration.
Stores every calendar and time component of the duration.
years - whole yearsmonths - whole monthsdays - whole dayshours - hoursminutes - minutesseconds - secondsmillis - millisecondsStores the day and time components. Years and months are zero.
days - whole dayshours - hoursminutes - minutesseconds - secondsmillis - millisecondsOrders durations by toMilliseconds(), so years and months use the ChronoUnit estimates and the shorter units are exact.
other - the duration to compare withThe date this duration ago.
DEQUIRKED (A): the time-of-day is preserved (no flooring to midnight), uniformly for all duration kinds.
Returns the stored day count.
Helper for computing dates relative to the current time. DEQUIRKED (A): time-of-day preserved.
Returns the stored hour count.
Returns the stored millisecond count.
Returns the stored minute count.
Returns the stored month count.
Returns the stored second count.
Returns the stored year count.
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.
Lists each non-zero component. Seconds and milliseconds are combined into one
fractional-seconds term, with the millisecond part padded to three digits.
A duration whose components are all zero is "0".
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.