- All Implemented Interfaces:
Serializable
,Comparable<YearToMonth>
,Interval
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:
-
Constructor Summary
ConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionfinal YearToMonth
abs()
Get the absolute value of the interval (set its sign to positive)final int
compareTo
(YearToMonth that) final double
final boolean
final float
final int
final int
getSign()
The sign of the intervalfinal int
getYears()
final int
hashCode()
final int
intValue()
final long
static YearToMonth
Parse a standard SQL string representation of aINTERVAL MONTH
.final YearToMonth
neg()
Negate the interval (change its sign)final Duration
Get a duration representation of this interval.final String
toString()
static YearToMonth
Parse a string representation of aINTERVAL YEAR TO MONTH
.static YearToMonth
Parse a standard SQL string representation of aINTERVAL YEAR
.static YearToMonth
yearToMonth
(String string) Parse a standard SQL string representation of aINTERVAL YEAR TO MONTH
.Methods inherited from class java.lang.Number
byteValue, shortValue
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
-
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
Parse a string representation of aINTERVAL YEAR TO MONTH
.- Parameters:
string
- A string representation of the form[+|-][years]-[months]
- Returns:
- The parsed
YEAR TO MONTH
object, ornull
if the string could not be parsed.
-
year
Parse a standard SQL string representation of aINTERVAL YEAR
.- Parameters:
string
- A string representation of the form[+|-][years]
- Returns:
- The parsed
YEAR
object, ornull
if the string could not be parsed.
-
yearToMonth
Parse a standard SQL string representation of aINTERVAL YEAR TO MONTH
.- Parameters:
string
- A string representation of the form[+|-][years]-[months]
- Returns:
- The parsed
YEAR TO MONTH
object, ornull
if the string could not be parsed.
-
month
Parse a standard SQL string representation of aINTERVAL MONTH
.- Parameters:
string
- A string representation of the form[+|-][months]
- Returns:
- The parsed
MONTH
object, ornull
if the string could not be parsed.
-
toDuration
Description copied from interface:Interval
Get a duration representation of this interval.There is an obvious
Duration
representation forDayToSecond
intervals. If the interval containsYearMonth
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 interfaceInterval
-
neg
Description copied from interface:Interval
Negate the interval (change its sign) -
abs
Description copied from interface:Interval
Get 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:Interval
The sign of the interval -
intValue
public final int intValue() -
longValue
public final long longValue() -
floatValue
public final float floatValue()- Specified by:
floatValue
in interfaceInterval
- Specified by:
floatValue
in classNumber
- See Also:
-
doubleValue
public final double doubleValue()- Specified by:
doubleValue
in interfaceInterval
- Specified by:
doubleValue
in classNumber
- See Also:
-
compareTo
- Specified by:
compareTo
in interfaceComparable<YearToMonth>
-
hashCode
public final int hashCode() -
equals
-
toString
-