Package org.apache.groovy.dateutil
Class TimeCategory
java.lang.Object
org.apache.groovy.dateutil.TimeCategory
A dequirked,
java.util.Date-flavored parallel to the legacy
groovy.time.TimeCategory. Use as:
use (org.apache.groovy.dateutil.TimeCategory) {
println 1.minute.from.now
println 10.hours.ago
def someDate = new Date()
println someDate - 3.months
}
Differences from the legacy class: the deprecated getTimeZone and the
getDaylightSavingsOffset helpers are dropped, and .ago/.from.now
preserve the time-of-day (see BaseDuration).- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DurationSame day duration asgetDays(Integer).static DurationADurationofselfdays.static TimeDurationSame hour duration asgetHours(Integer).static TimeDurationATimeDurationofselfhours.static TimeDurationgetMillisecond(Integer self) Same millisecond duration asgetMilliseconds(Integer).static TimeDurationgetMilliseconds(Integer self) ATimeDurationofselfmilliseconds.static TimeDurationSame minute duration asgetMinutes(Integer).static TimeDurationgetMinutes(Integer self) ATimeDurationofselfminutes.static DatumDependentDurationSame month duration asgetMonths(Integer).static DatumDependentDurationADatumDependentDurationwhose month component isself.static TimeDurationSame second duration asgetSeconds(Integer).static TimeDurationgetSeconds(Integer self) ATimeDurationofselfseconds.static DurationSame week duration asgetWeeks(Integer).static DurationADurationofself * 7days.static DatumDependentDurationSame year duration asgetYears(Integer).static DatumDependentDurationADatumDependentDurationwhose year component isself.static TimeDurationReturnslhs - rhsas aTimeDuration.static Dateminus(Date date, BaseDuration duration) Subtracts each component ofdurationfromdate.static Dateplus(Date date, BaseDuration duration) Addsdurationtodateby calendar field.
-
Constructor Details
-
TimeCategory
public TimeCategory()
-
-
Method Details
-
plus
Addsdurationtodateby calendar field.- Parameters:
date- the starting dateduration- the amount to add- Returns:
- the shifted date
-
minus
Subtracts each component ofdurationfromdate. Hours, minutes, seconds, and milliseconds move the time of day.- Parameters:
date- the starting dateduration- the amount to subtract- Returns:
- the shifted date
-
minus
Returnslhs - rhsas aTimeDuration. The millisecond difference is split into days, hours, minutes, seconds, and milliseconds by integer division.- Parameters:
lhs- the later date when the result is positiverhs- the date subtracted fromlhs- Returns:
- the difference
-
getMonths
ADatumDependentDurationwhose month component isself.- Parameters:
self- the number of months- Returns:
- that duration
-
getMonth
Same month duration asgetMonths(Integer).- Parameters:
self- the number of months- Returns:
- that duration
-
getYears
ADatumDependentDurationwhose year component isself.- Parameters:
self- the number of years- Returns:
- that duration
-
getYear
Same year duration asgetYears(Integer).- Parameters:
self- the number of years- Returns:
- that duration
-
getWeeks
ADurationofself * 7days.- Parameters:
self- the number of weeks- Returns:
- that duration
-
getWeek
Same week duration asgetWeeks(Integer).- Parameters:
self- the number of weeks- Returns:
- that duration
-
getDays
ADurationofselfdays.- Parameters:
self- the number of days- Returns:
- that duration
-
getDay
Same day duration asgetDays(Integer).- Parameters:
self- the number of days- Returns:
- that duration
-
getHours
ATimeDurationofselfhours.- Parameters:
self- the number of hours- Returns:
- that duration
-
getHour
Same hour duration asgetHours(Integer).- Parameters:
self- the number of hours- Returns:
- that duration
-
getMinutes
ATimeDurationofselfminutes.- Parameters:
self- the number of minutes- Returns:
- that duration
-
getMinute
Same minute duration asgetMinutes(Integer).- Parameters:
self- the number of minutes- Returns:
- that duration
-
getSeconds
ATimeDurationofselfseconds.- Parameters:
self- the number of seconds- Returns:
- that duration
-
getSecond
Same second duration asgetSeconds(Integer).- Parameters:
self- the number of seconds- Returns:
- that duration
-
getMilliseconds
ATimeDurationofselfmilliseconds.- Parameters:
self- the number of milliseconds- Returns:
- that duration
-
getMillisecond
Same millisecond duration asgetMilliseconds(Integer).- Parameters:
self- the number of milliseconds- Returns:
- that duration
-