Module org.jooq

Class YearToMonth

java.lang.Object
java.lang.Number
org.jooq.types.YearToMonth
All Implemented Interfaces:
Serializable, Comparable<YearToMonth>, Interval

public final class YearToMonth extends Number implements Interval, Comparable<YearToMonth>
An implementation for the SQL standard INTERVAL YEAR TO MONTH data type.

YearToMonth is a Number whose Number.intValue() represents the number of months of the interval.

Note: only a few databases actually support this data type on its own. You can still use it for date time arithmetic in other databases, though, through Field.add(Field) and Field.sub(Field) Databases that have been observed to natively support INTERVAL data types are:

These dialects have been observed to partially support INTERVAL data types in date time arithmetic functions, such as TIMESTAMPADD, and TIMESTAMPDIFF:

Author:
Lukas Eder
See Also:
Interval, Serialized Form
  • Constructor Details

    • YearToMonth

      public YearToMonth()
      Create a new year-month interval.
    • YearToMonth

      public YearToMonth(int years)
      Create a new year-month interval.
    • YearToMonth

      public YearToMonth(int years, int months)
      Create a new year-month interval.
  • Method Details

    • valueOf

      public static YearToMonth valueOf(String string)
      Parse a string representation of a INTERVAL YEAR TO MONTH.
      Parameters:
      string - A string representation of the form [+|-][years]-[months]
      Returns:
      The parsed YEAR TO MONTH object, or null if the string could not be parsed.
    • year

      public static YearToMonth year(String string)
      Parse a standard SQL string representation of a INTERVAL YEAR.
      Parameters:
      string - A string representation of the form [+|-][years]
      Returns:
      The parsed YEAR object, or null if the string could not be parsed.
    • yearToMonth

      public static YearToMonth yearToMonth(String string)
      Parse a standard SQL string representation of a INTERVAL YEAR TO MONTH.
      Parameters:
      string - A string representation of the form [+|-][years]-[months]
      Returns:
      The parsed YEAR TO MONTH object, or null if the string could not be parsed.
    • month

      public static YearToMonth month(String string)
      Parse a standard SQL string representation of a INTERVAL MONTH.
      Parameters:
      string - A string representation of the form [+|-][months]
      Returns:
      The parsed MONTH object, or null if the string could not be parsed.
    • toDuration

      public final Duration toDuration()
      Description copied from interface: Interval
      Get a duration representation of this interval.

      There is an obvious Duration representation for DayToSecond intervals. If the interval contains YearMonth information, then the corresponding duration will use:

      • 1 year = 365.25 days
      • 1 month = 30 days

      This corresponds to PostgreSQL's EXTRACT(EPOCH FROM my_interval) behaviour.

      Specified by:
      toDuration in interface Interval
    • neg

      public final YearToMonth neg()
      Description copied from interface: Interval
      Negate the interval (change its sign)
      Specified by:
      neg in interface Interval
    • abs

      public final YearToMonth abs()
      Description copied from interface: Interval
      Get the absolute value of the interval (set its sign to positive)
      Specified by:
      abs in interface Interval
    • getYears

      public final int getYears()
    • getMonths

      public final int getMonths()
    • getSign

      public final int getSign()
      Description copied from interface: Interval
      The sign of the interval
      Specified by:
      getSign in interface Interval
      Returns:
      1 for positive or zero, -1 for negative
    • intValue

      public final int intValue()
      Specified by:
      intValue in interface Interval
      Specified by:
      intValue in class Number
      See Also:
      Number.intValue()
    • longValue

      public final long longValue()
      Specified by:
      longValue in interface Interval
      Specified by:
      longValue in class Number
      See Also:
      Number.longValue()
    • floatValue

      public final float floatValue()
      Specified by:
      floatValue in interface Interval
      Specified by:
      floatValue in class Number
      See Also:
      Number.floatValue()
    • doubleValue

      public final double doubleValue()
      Specified by:
      doubleValue in interface Interval
      Specified by:
      doubleValue in class Number
      See Also:
      Number.doubleValue()
    • compareTo

      public final int compareTo(YearToMonth that)
      Specified by:
      compareTo in interface Comparable<YearToMonth>
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object