-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DayToSecond,YearToMonth,YearToSecond
public interface Interval extends Serializable
A substitute for JDBC's missingjava.sql.Intervaldata type.JDBC lacks an important data type that is present in most SQL databases:
INTERVAL. The SQL:2008 standard states that there are two types of intervals:4.6.3 Intervals
There are two classes of intervals. One class, called year-month intervals, has an express or implied datetime precision that includes no fields other than YEAR and MONTH, though not both are required. The other class, called day-time intervals, has an express or implied interval precision that can include any fields other than YEAR or MONTH.
INTERVALcan be combined with date time data types according to the following operation table:Operand 1 Operator Operand 2 Result Type Datetime – Datetime Interval Datetime + or – Interval Datetime Interval + Datetime Datetime Interval + or – Interval Interval Interval * or / Numeric Interval Numeric * Interval Interval Interval implementations can be expected to also also extend
Number.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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Intervalabs()Get the absolute value of the interval (set its sign to positive)bytebyteValue()doubledoubleValue()floatfloatValue()intgetSign()The sign of the intervalintintValue()longlongValue()Intervalneg()Negate the interval (change its sign)shortshortValue()DurationtoDuration()Get a duration representation of this interval.
-
-
-
Method Detail
-
neg
Interval neg()
Negate the interval (change its sign)
-
abs
Interval abs()
Get the absolute value of the interval (set its sign to positive)
-
getSign
int getSign()
The sign of the interval- Returns:
1for positive or zero,-1for negative
-
doubleValue
double doubleValue()
- See Also:
Number.doubleValue()
-
floatValue
float floatValue()
- See Also:
Number.floatValue()
-
longValue
long longValue()
- See Also:
Number.longValue()
-
intValue
int intValue()
- See Also:
Number.intValue()
-
byteValue
byte byteValue()
- See Also:
Number.byteValue()
-
shortValue
short shortValue()
- See Also:
Number.shortValue()
-
toDuration
Duration toDuration()
Get 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.
-
-