Package org.apache.groovy.datetime

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

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `TimeCategory.From`
  Helper returned by `getFrom(java.time.Duration)`, supporting the `.now` / `.today` suffix.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TimeCategory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static LocalDateTime`
  `getAgo(Duration self)`
  The `LocalDateTime` this time-based duration before now (time-of-day preserved).
  `static LocalDate`
  `getAgo(Period self)`
  The `LocalDate` this date-based period before today.
  `static Period`
  `getDay(Integer self)`
  `static Period`
  `getDays(Integer self)`
  `static TimeCategory.From`
  `getFrom(Duration self)`
  Helper for `duration.from.now`; the resulting temporal is a `LocalDateTime`.
  `static TimeCategory.From`
  `getFrom(Period self)`
  Helper for `period.from.now`; the resulting temporal is a `LocalDate`.
  `static Duration`
  `getHour(Integer self)`
  `static Duration`
  `getHours(Integer self)`
  `static Duration`
  `getMillisecond(Integer self)`
  `static Duration`
  `getMilliseconds(Integer self)`
  `static Duration`
  `getMinute(Integer self)`
  `static Duration`
  `getMinutes(Integer self)`
  `static Period`
  `getMonth(Integer self)`
  `static Period`
  `getMonths(Integer self)`
  `static Duration`
  `getNanosecond(Integer self)`
  `static Duration`
  `getNanoseconds(Integer self)`
  `static Duration`
  `getSecond(Integer self)`
  `static Duration`
  `getSeconds(Integer self)`
  `static Period`
  `getWeek(Integer self)`
  `static Period`
  `getWeeks(Integer self)`
  `static Period`
  `getYear(Integer self)`
  `static Period`
  `getYears(Integer self)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### TimeCategory

    public TimeCategory()

- ## Method Details

  - ### getNanoseconds

    public static Duration getNanoseconds(Integer self)

  - ### getNanosecond

    public static Duration getNanosecond(Integer self)

  - ### getMilliseconds

    public static Duration getMilliseconds(Integer self)

  - ### getMillisecond

    public static Duration getMillisecond(Integer self)

  - ### getSeconds

    public static Duration getSeconds(Integer self)

  - ### getSecond

    public static Duration getSecond(Integer self)

  - ### getMinutes

    public static Duration getMinutes(Integer self)

  - ### getMinute

    public static Duration getMinute(Integer self)

  - ### getHours

    public static Duration getHours(Integer self)

  - ### getHour

    public static Duration getHour(Integer self)

  - ### getDays

    public static Period getDays(Integer self)

  - ### getDay

    public static Period getDay(Integer self)

  - ### getWeeks

    public static Period getWeeks(Integer self)

  - ### getWeek

    public static Period getWeek(Integer self)

  - ### getMonths

    public static Period getMonths(Integer self)

  - ### getMonth

    public static Period getMonth(Integer self)

  - ### getYears

    public static Period getYears(Integer self)

  - ### getYear

    public static Period getYear(Integer self)

  - ### getAgo

    public static LocalDateTime getAgo(Duration self)
    The `LocalDateTime` this time-based duration before now (time-of-day preserved).

  - ### getAgo

    public static LocalDate getAgo(Period self)
    The `LocalDate` this date-based period before today.

  - ### getFrom

    public static TimeCategory.From getFrom(Duration self)
    Helper for `duration.from.now`; the resulting temporal is a `LocalDateTime`.

  - ### getFrom

    public static TimeCategory.From getFrom(Period self)
    Helper for `period.from.now`; the resulting temporal is a `LocalDate`.