Package org.apache.groovy.dateutil
Class BaseDuration
java.lang.Object
org.apache.groovy.dateutil.BaseDuration
- All Implemented Interfaces:
Comparable<BaseDuration>
- Direct Known Subclasses:
DatumDependentDuration,Duration
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) useChronoUnit's estimated durations rather than resolving againstnew Date()("now"), so the result no longer depends on when it is called.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHelper for computing dates relative to the current time. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseDuration(int days, int hours, int minutes, int seconds, int millis) protectedBaseDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis) -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(BaseDuration other) getAgo()The date this duration ago.intgetDays()getFrom()Helper for computing dates relative to the current time.intgetHours()intintintintintgetYears()Adds this duration to the supplied date.longConverts this duration to milliseconds.toString()
-
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
Adds this duration to the supplied date. -
toMilliseconds
public long toMilliseconds()Converts this duration to milliseconds.DEQUIRKED (B): deterministic. Years and months use
ChronoUnitestimates (a year is exactly 12 estimated months, so1.year == 12.months); days and below are exact assuming 24-hour days. The result never depends on the current 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
Helper for computing dates relative to the current time. DEQUIRKED (A): time-of-day preserved. -
compareTo
- Specified by:
compareToin interfaceComparable<BaseDuration>
-
toString
-