Class TimeCategory

java.lang.Object
org.apache.groovy.datetime.TimeCategory

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).