- java.lang.Object
-
- java.lang.Number
-
- org.jooq.types.YearToSecond
-
- All Implemented Interfaces:
Serializable
,Comparable<YearToSecond>
,Interval
public final class YearToSecond extends Number implements Interval, Comparable<YearToSecond>
A combinedYearToMonth
/DayToSecond
interval.Some databases (e.g. PostgreSQL) allow for mixing
YEAR TO MONTH
andDAY TO SECOND
intervals, despite the many questions such a combination raises. TheYearToSecond
type intends to model such vendor specific intervals.The numeric value of this interval corresponds to its "context free" number of milliseconds. While the
DayToSecond
interval component can provide such a value easily (being independent of time zones, daylight saving times, leap years, or leap seconds), theYearToMonth
component cannot. The implemented rules are those of PostgreSQL:- A day has 86400 seconds
- A month has 30 days
- A year has 365.25 days
- A year has 12 months
Examples:
P11M
has 330 daysP1Y-1M
has 330 daysP1Y
has 365.25 daysP1Y1M
has 396.25 days
- Author:
- Lukas Eder
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description YearToSecond(YearToMonth yearToMonth, DayToSecond dayToSecond)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description YearToSecond
abs()
Get the absolute value of the interval (set its sign to positive)int
compareTo(YearToSecond that)
double
doubleValue()
boolean
equals(Object obj)
float
floatValue()
int
getDays()
Get the day-part of this intervalDayToSecond
getDayToSecond()
int
getHours()
Get the hour-part of this intervalint
getMicro()
Get the (truncated) micro-part of this intervalint
getMilli()
Get the (truncated) milli-part of this intervalint
getMinutes()
Get the minute-part of this intervalint
getMonths()
int
getNano()
Get the nano-part of this intervalint
getSeconds()
Get the second-part of this intervalint
getSign()
The sign of the intervalint
getYears()
YearToMonth
getYearToMonth()
int
hashCode()
int
intValue()
long
longValue()
YearToSecond
neg()
Negate the interval (change its sign)Duration
toDuration()
Get a duration representation of this interval.String
toString()
static YearToSecond
valueOf(double milli)
Load aDouble
representation of aINTERVAL YEAR TO SECOND
by assuming standard 24 hour days and 60 second minutes.static YearToSecond
valueOf(String string)
Parse a string representation of aINTERVAL YEAR TO SECOND
static YearToSecond
valueOf(Duration duration)
Transform aDuration
into aYearToSecond
interval by taking its number of milliseconds.static YearToSecond
valueOf(Period period)
Transform aPeriod
into aYearToSecond
interval.-
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 Detail
-
YearToSecond
public YearToSecond(YearToMonth yearToMonth, DayToSecond dayToSecond)
-
-
Method Detail
-
valueOf
public static YearToSecond valueOf(double milli)
Load aDouble
representation of aINTERVAL YEAR TO SECOND
by assuming standard 24 hour days and 60 second minutes.- Parameters:
milli
- The number of milliseconds as a fractional number- Returns:
- The loaded
INTERVAL DAY TO SECOND
object
-
valueOf
public static YearToSecond valueOf(Duration duration)
Transform aDuration
into aYearToSecond
interval by taking its number of milliseconds.
-
toDuration
public final Duration 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
-
valueOf
public static YearToSecond valueOf(Period period)
Transform aPeriod
into aYearToSecond
interval.
-
valueOf
public static YearToSecond valueOf(String string)
Parse a string representation of aINTERVAL YEAR TO SECOND
- Parameters:
string
- A string representation of the form[+|-][years]-[months] [+|-][days] [hours]:[minutes]:[seconds].[fractional seconds]
- Returns:
- The parsed
YEAR TO SECOND
object, ornull
if the string could not be parsed.
-
neg
public final YearToSecond neg()
Description copied from interface:Interval
Negate the interval (change its sign)
-
abs
public final YearToSecond abs()
Description copied from interface:Interval
Get the absolute value of the interval (set its sign to positive)
-
getYearToMonth
public final YearToMonth getYearToMonth()
-
getDayToSecond
public final DayToSecond getDayToSecond()
-
getYears
public final int getYears()
-
getMonths
public final int getMonths()
-
getDays
public final int getDays()
Get the day-part of this interval
-
getHours
public final int getHours()
Get the hour-part of this interval
-
getMinutes
public final int getMinutes()
Get the minute-part of this interval
-
getSeconds
public final int getSeconds()
Get the second-part of this interval
-
getMilli
public final int getMilli()
Get the (truncated) milli-part of this interval
-
getMicro
public final int getMicro()
Get the (truncated) micro-part of this interval
-
getNano
public final int getNano()
Get the nano-part of this interval
-
getSign
public final int getSign()
Description copied from interface:Interval
The sign of the interval
-
intValue
public final int intValue()
- Specified by:
intValue
in interfaceInterval
- Specified by:
intValue
in classNumber
- See Also:
Number.intValue()
-
longValue
public final long longValue()
- Specified by:
longValue
in interfaceInterval
- Specified by:
longValue
in classNumber
- See Also:
Number.longValue()
-
floatValue
public final float floatValue()
- Specified by:
floatValue
in interfaceInterval
- Specified by:
floatValue
in classNumber
- See Also:
Number.floatValue()
-
doubleValue
public final double doubleValue()
- Specified by:
doubleValue
in interfaceInterval
- Specified by:
doubleValue
in classNumber
- See Also:
Number.doubleValue()
-
compareTo
public final int compareTo(YearToSecond that)
- Specified by:
compareTo
in interfaceComparable<YearToSecond>
-
-