Package groovy.time

Class TimeCategory

java.lang.Object
groovy.time.TimeCategory

public class TimeCategory extends Object
Apply a number of methods to allow convenient Date/Time manipulation,such as:
 use (groovy.time.TimeCategory) {
     // application on numbers:
     println 1.minute.from.now
     println 10.hours.ago

     // application on dates
     def someDate = new Date()
     println someDate - 3.months
 }
 
See Also:
  • Constructor Details

    • TimeCategory

      public TimeCategory()
  • Method Details

    • plus

      public static Date plus(Date date, BaseDuration duration)
      Adds a duration to a date.
      Parameters:
      date - the base date
      duration - the duration to add
      Returns:
      the adjusted date
    • minus

      public static Date minus(Date date, BaseDuration duration)
      Subtracts a duration from a date.
      Parameters:
      date - the base date
      duration - the duration to subtract
      Returns:
      the adjusted date
    • getTimeZone

      @Deprecated public static TimeZone getTimeZone(Date self)
      Deprecated.
      Retrieves the default TimeZone for a date by using the default Locale settings. Recommended that you use TimeZone.getDefault() instead.
      Parameters:
      self - a Date
      Returns:
      the TimeZone
    • getDaylightSavingsOffset

      public static Duration getDaylightSavingsOffset(Date self)
      Get the DST offset (if any) for the default locale and the given date.
      Parameters:
      self - a Date
      Returns:
      the DST offset as a Duration.
    • getDaylightSavingsOffset

      public static Duration getDaylightSavingsOffset(BaseDuration self)
      Gets the daylight savings offset for the supplied duration interpreted as a date.
      Parameters:
      self - the duration to inspect
      Returns:
      the DST offset as a duration
    • getRelativeDaylightSavingsOffset

      public static Duration getRelativeDaylightSavingsOffset(Date self, Date other)
      Return a Duration representing the DST difference (if any) between two dates. i.e. if one date is before the DST changeover, and the other date is after, the resulting duration will represent the DST offset.
      Parameters:
      self - a Date
      other - another Date
      Returns:
      a Duration
    • minus

      public static TimeDuration minus(Date lhs, Date rhs)
      Subtract one date from the other.
      Parameters:
      lhs - a Date
      rhs - another Date
      Returns:
      a Duration
    • getMonths

      public static DatumDependentDuration getMonths(Integer self)
      Returns a month-based duration for the supplied number of months.
      Parameters:
      self - the number of months
      Returns:
      the corresponding duration
    • getMonth

      public static DatumDependentDuration getMonth(Integer self)
      Parameters:
      self - the number of months
      Returns:
      the corresponding duration
    • getYears

      public static DatumDependentDuration getYears(Integer self)
      Returns a year-based duration for the supplied number of years.
      Parameters:
      self - the number of years
      Returns:
      the corresponding duration
    • getYear

      public static DatumDependentDuration getYear(Integer self)
      Parameters:
      self - the number of years
      Returns:
      the corresponding duration
    • getWeeks

      public static Duration getWeeks(Integer self)
      Returns a week-based duration for the supplied number of weeks.
      Parameters:
      self - the number of weeks
      Returns:
      the corresponding duration
    • getWeek

      public static Duration getWeek(Integer self)
      Parameters:
      self - the number of weeks
      Returns:
      the corresponding duration
    • getDays

      public static Duration getDays(Integer self)
      Returns a day-based duration for the supplied number of days.
      Parameters:
      self - the number of days
      Returns:
      the corresponding duration
    • getDay

      public static Duration getDay(Integer self)
      Alias for getDays(Integer).
      Parameters:
      self - the number of days
      Returns:
      the corresponding duration
    • getHours

      public static TimeDuration getHours(Integer self)
      Returns an hour-based duration for the supplied number of hours.
      Parameters:
      self - the number of hours
      Returns:
      the corresponding duration
    • getHour

      public static TimeDuration getHour(Integer self)
      Parameters:
      self - the number of hours
      Returns:
      the corresponding duration
    • getMinutes

      public static TimeDuration getMinutes(Integer self)
      Returns a minute-based duration for the supplied number of minutes.
      Parameters:
      self - the number of minutes
      Returns:
      the corresponding duration
    • getMinute

      public static TimeDuration getMinute(Integer self)
      Parameters:
      self - the number of minutes
      Returns:
      the corresponding duration
    • getSeconds

      public static TimeDuration getSeconds(Integer self)
      Returns a second-based duration for the supplied number of seconds.
      Parameters:
      self - the number of seconds
      Returns:
      the corresponding duration
    • getSecond

      public static TimeDuration getSecond(Integer self)
      Parameters:
      self - the number of seconds
      Returns:
      the corresponding duration
    • getMilliseconds

      public static TimeDuration getMilliseconds(Integer self)
      Returns a millisecond-based duration for the supplied number of milliseconds.
      Parameters:
      self - the number of milliseconds
      Returns:
      the corresponding duration
    • getMillisecond

      public static TimeDuration getMillisecond(Integer self)
      Parameters:
      self - the number of milliseconds
      Returns:
      the corresponding duration