Package groovy.time
Class BaseDuration
java.lang.Object
groovy.time.BaseDuration
- All Implemented Interfaces:
Comparable<BaseDuration>
- Direct Known Subclasses:
DatumDependentDuration,Duration
Base class for date and time durations.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHelper for computing dates relative to the current time. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intDay component.protected final intHour component.protected final intMillisecond component.protected final intMinute component.protected final intMonth component.protected final intSecond component.protected final intYear component. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseDuration(int days, int hours, int minutes, int seconds, int millis) Creates a duration without year or month components.protectedBaseDuration(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 TypeMethodDescriptionintcompareTo(BaseDuration otherDuration) Compares this duration with another by their millisecond values.abstract DategetAgo()Returns the date represented by this duration ago.intgetDays()Returns the day component.abstract BaseDuration.FromgetFrom()Returns a helper for computing dates relative to now.intgetHours()Returns the hour component.intReturns the millisecond component.intReturns the minute component.intReturns the month component.intReturns the second component.intgetYears()Returns the year component.Adds this duration to the supplied date.abstract longConverts this duration to milliseconds.toString()Returns a human-readable representation of this duration.
-
Field Details
-
years
protected final int yearsYear component. -
months
protected final int monthsMonth component. -
days
protected final int daysDay component. -
hours
protected final int hoursHour component. -
minutes
protected final int minutesMinute component. -
seconds
protected final int secondsSecond component. -
millis
protected final int millisMillisecond 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 componentmonths- the month componentdays- the day componenthours- the hour componentminutes- the minute componentseconds- the second componentmillis- 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 componenthours- the hour componentminutes- the minute componentseconds- the second componentmillis- 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
Adds this duration to the supplied date.- Parameters:
date- the date to adjust- Returns:
- the adjusted date
-
toString
Returns a human-readable representation of this duration. -
toMilliseconds
public abstract long toMilliseconds()Converts this duration to milliseconds.- Returns:
- the duration in milliseconds
-
getAgo
Returns the date represented by this duration ago.- Returns:
- the computed date
-
getFrom
Returns a helper for computing dates relative to now.- Returns:
- the relative-date helper
-
compareTo
Compares this duration with another by their millisecond values.- Specified by:
compareToin interfaceComparable<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
-