Class TimeCategory

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

public class TimeCategory extends Object
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 Details

    • TimeCategory

      public TimeCategory()
  • Method Details

    • plus

      public static Date plus(Date date, BaseDuration duration)
      Adds duration to date by calendar field.
      Parameters:
      date - the starting date
      duration - the amount to add
      Returns:
      the shifted date
    • minus

      public static Date minus(Date date, BaseDuration duration)
      Subtracts each component of duration from date. Hours, minutes, seconds, and milliseconds move the time of day.
      Parameters:
      date - the starting date
      duration - the amount to subtract
      Returns:
      the shifted date
    • minus

      public static TimeDuration minus(Date lhs, Date rhs)
      Returns lhs - rhs as a TimeDuration. The millisecond difference is split into days, hours, minutes, seconds, and milliseconds by integer division.
      Parameters:
      lhs - the later date when the result is positive
      rhs - the date subtracted from lhs
      Returns:
      the difference
    • getMonths

      public static DatumDependentDuration getMonths(Integer self)
      A DatumDependentDuration whose month component is self.
      Parameters:
      self - the number of months
      Returns:
      that duration
    • getMonth

      public static DatumDependentDuration getMonth(Integer self)
      Same month duration as getMonths(Integer).
      Parameters:
      self - the number of months
      Returns:
      that duration
    • getYears

      public static DatumDependentDuration getYears(Integer self)
      A DatumDependentDuration whose year component is self.
      Parameters:
      self - the number of years
      Returns:
      that duration
    • getYear

      public static DatumDependentDuration getYear(Integer self)
      Same year duration as getYears(Integer).
      Parameters:
      self - the number of years
      Returns:
      that duration
    • getWeeks

      public static Duration getWeeks(Integer self)
      A Duration of self * 7 days.
      Parameters:
      self - the number of weeks
      Returns:
      that duration
    • getWeek

      public static Duration getWeek(Integer self)
      Same week duration as getWeeks(Integer).
      Parameters:
      self - the number of weeks
      Returns:
      that duration
    • getDays

      public static Duration getDays(Integer self)
      A Duration of self days.
      Parameters:
      self - the number of days
      Returns:
      that duration
    • getDay

      public static Duration getDay(Integer self)
      Same day duration as getDays(Integer).
      Parameters:
      self - the number of days
      Returns:
      that duration
    • getHours

      public static TimeDuration getHours(Integer self)
      A TimeDuration of self hours.
      Parameters:
      self - the number of hours
      Returns:
      that duration
    • getHour

      public static TimeDuration getHour(Integer self)
      Same hour duration as getHours(Integer).
      Parameters:
      self - the number of hours
      Returns:
      that duration
    • getMinutes

      public static TimeDuration getMinutes(Integer self)
      A TimeDuration of self minutes.
      Parameters:
      self - the number of minutes
      Returns:
      that duration
    • getMinute

      public static TimeDuration getMinute(Integer self)
      Same minute duration as getMinutes(Integer).
      Parameters:
      self - the number of minutes
      Returns:
      that duration
    • getSeconds

      public static TimeDuration getSeconds(Integer self)
      A TimeDuration of self seconds.
      Parameters:
      self - the number of seconds
      Returns:
      that duration
    • getSecond

      public static TimeDuration getSecond(Integer self)
      Same second duration as getSeconds(Integer).
      Parameters:
      self - the number of seconds
      Returns:
      that duration
    • getMilliseconds

      public static TimeDuration getMilliseconds(Integer self)
      A TimeDuration of self milliseconds.
      Parameters:
      self - the number of milliseconds
      Returns:
      that duration
    • getMillisecond

      public static TimeDuration getMillisecond(Integer self)
      Same millisecond duration as getMilliseconds(Integer).
      Parameters:
      self - the number of milliseconds
      Returns:
      that duration