Class YearToMonth
- java.lang.Object
-
- java.lang.Number
-
- org.jooq.types.YearToMonth
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<YearToMonth>,Interval
public final class YearToMonth extends java.lang.Number implements Interval, java.lang.Comparable<YearToMonth>
An implementation for the SQL standardINTERVAL YEAR TO MONTHdata type.YearToMonthis aNumberwhoseNumber.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)andField.sub(Field)Databases that have been observed to natively supportINTERVALdata types are:These dialects have been observed to partially support
INTERVALdata types in date time arithmetic functions, such asTIMESTAMPADD, andTIMESTAMPDIFF:- Author:
- Lukas Eder
- See Also:
Interval, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description YearToMonth()Create a new year-month interval.YearToMonth(int years)Create a new year-month interval.YearToMonth(int years, int months)Create a new year-month interval.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description YearToMonthabs()Get the absolute value of the interval (set its sign to positive)intcompareTo(YearToMonth that)doubledoubleValue()booleanequals(java.lang.Object obj)floatfloatValue()intgetMonths()intgetSign()The sign of the intervalintgetYears()inthashCode()intintValue()longlongValue()YearToMonthneg()Negate the interval (change its sign)java.time.DurationtoDuration()Get a duration representation of this interval.java.lang.StringtoString()static YearToMonthvalueOf(java.lang.String string)Parse a string representation of aINTERVAL YEAR TO MONTH-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jooq.types.Interval
byteValue, shortValue
-
-
-
-
Method Detail
-
valueOf
public static YearToMonth valueOf(java.lang.String string)
Parse a string representation of aINTERVAL YEAR TO MONTH- Parameters:
string- A string representation of the form[+|-][years]-[months]- Returns:
- The parsed
YEAR TO MONTHobject, ornullif the string could not be parsed.
-
toDuration
public final java.time.Duration toDuration()
Description copied from interface:IntervalGet a duration representation of this interval.There is an obvious
Durationrepresentation forDayToSecondintervals. If the interval containsYearMonthinformation, 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:
toDurationin interfaceInterval
-
neg
public final YearToMonth neg()
Description copied from interface:IntervalNegate the interval (change its sign)
-
abs
public final YearToMonth abs()
Description copied from interface:IntervalGet the absolute value of the interval (set its sign to positive)
-
getYears
public final int getYears()
-
getMonths
public final int getMonths()
-
getSign
public final int getSign()
Description copied from interface:IntervalThe sign of the interval
-
intValue
public final int intValue()
-
longValue
public final long longValue()
-
floatValue
public final float floatValue()
- Specified by:
floatValuein interfaceInterval- Specified by:
floatValuein classjava.lang.Number- See Also:
Number.floatValue()
-
doubleValue
public final double doubleValue()
- Specified by:
doubleValuein interfaceInterval- Specified by:
doubleValuein classjava.lang.Number- See Also:
Number.doubleValue()
-
compareTo
public final int compareTo(YearToMonth that)
- Specified by:
compareToin interfacejava.lang.Comparable<YearToMonth>
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-