public class TimeCategory
extends Object
A java.time-based DSL for convenient date/time manipulation, the modern
counterpart to the legacy groovy.time.TimeCategory. Numbers gain properties
that produce Duration (time-based amounts) or Period (date-based
amounts), which compose with the java.time types via their native arithmetic:
import java.time.LocalDate
import java.time.LocalDateTime
use (org.apache.groovy.datetime.TimeCategory) {
assert LocalDate.of(2000, 1, 1) + 2.months == LocalDate.of(2000, 3, 1)
assert 2.days.ago instanceof LocalDate
assert 1.hour.from.now instanceof LocalDateTime
}
Time-based units (nanoseconds, milliseconds, seconds,
minutes, hours) yield a Duration; date-based units
(days, weeks, months, years) yield a Period.
The two are not combined into a single amount (as java.time intends); instead
they compose by chaining, e.g. someDateTime + 2.months + 3.hours.
Unlike the legacy DSL, .ago/.from.now never floor the time-of-day:
a Duration resolves against LocalDateTime.now (time preserved) and a
Period against LocalDate.now (date only, so no time component exists).
| Modifiers | Name | Description |
|---|---|---|
static class |
TimeCategory.From |
Helper returned by getFrom, supporting the .now / .today suffix. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static LocalDateTime |
getAgo(Duration self)The LocalDateTime this time-based duration before now (time-of-day preserved). |
|
public static LocalDate |
getAgo(Period self)The LocalDate this date-based period before today. |
|
public static Period |
getDay(Integer self)Same day period as getDays(Integer). |
|
public static Period |
getDays(Integer self)A Period of self days. |
|
public static TimeCategory.From |
getFrom(Duration self)Helper for duration.from.now; the resulting temporal is a LocalDateTime. |
|
public static TimeCategory.From |
getFrom(Period self)Helper for period.from.now; the resulting temporal is a LocalDate. |
|
public static Duration |
getHour(Integer self)Same hour duration as getHours(Integer). |
|
public static Duration |
getHours(Integer self)A Duration of self hours. |
|
public static Duration |
getMillisecond(Integer self)Same millisecond duration as getMilliseconds(Integer). |
|
public static Duration |
getMilliseconds(Integer self)A Duration of self milliseconds. |
|
public static Duration |
getMinute(Integer self)Same minute duration as getMinutes(Integer). |
|
public static Duration |
getMinutes(Integer self)A Duration of self minutes. |
|
public static Period |
getMonth(Integer self)Same month period as getMonths(Integer). |
|
public static Period |
getMonths(Integer self)A Period of self months. |
|
public static Duration |
getNanosecond(Integer self)Same nanosecond duration as getNanoseconds(Integer). |
|
public static Duration |
getNanoseconds(Integer self)A Duration of self nanoseconds. |
|
public static Duration |
getSecond(Integer self)Same second duration as getSeconds(Integer). |
|
public static Duration |
getSeconds(Integer self)A Duration of self seconds. |
|
public static Period |
getWeek(Integer self)Same week period as getWeeks(Integer). |
|
public static Period |
getWeeks(Integer self)A Period of self weeks. |
|
public static Period |
getYear(Integer self)Same year period as getYears(Integer). |
|
public static Period |
getYears(Integer self)A Period of self years. |
The LocalDateTime this time-based duration before now (time-of-day preserved).
Same day period as getDays(Integer).
self - the number of days A Period of self days.
self - the number of days Helper for duration.from.now; the resulting temporal is a LocalDateTime.
Helper for period.from.now; the resulting temporal is a LocalDate.
Same hour duration as getHours(Integer).
self - the number of hours A Duration of self hours.
self - the number of hoursSame millisecond duration as getMilliseconds(Integer).
self - the number of milliseconds A Duration of self milliseconds.
self - the number of millisecondsSame minute duration as getMinutes(Integer).
self - the number of minutes A Duration of self minutes.
self - the number of minutesSame month period as getMonths(Integer).
self - the number of months A Period of self months.
self - the number of monthsSame nanosecond duration as getNanoseconds(Integer).
self - the number of nanoseconds A Duration of self nanoseconds.
self - the number of nanosecondsSame second duration as getSeconds(Integer).
self - the number of seconds A Duration of self seconds.
self - the number of secondsSame week period as getWeeks(Integer).
self - the number of weeks A Period of self weeks.
self - the number of weeksSame year period as getYears(Integer).
self - the number of years