Package org.h2.util

# Class IntervalUtils

java.lang.Object
org.h2.util.IntervalUtils

public class IntervalUtils extends Object
This utility class contains interval conversion functions.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final BigInteger`
`NANOS_PER_DAY_BI`
The number of nanoseconds per day as BigInteger.

## Method Summary

Modifier and Type
Method
Description
`static StringBuilder`
`appendInterval(StringBuilder buff, IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Formats interval as a string and appends it to a specified string builder.
`static long`
`daysFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Returns days value of interval, if any.
`static long`
`hoursFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Returns hours value of interval, if any.
`static ValueInterval`
`intervalFromAbsolute(IntervalQualifier qualifier, BigInteger absolute)`
Converts absolute value to an interval value.
`static BigInteger`
`intervalToAbsolute(ValueInterval interval)`
Converts interval value to an absolute value.
`static long`
`minutesFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Returns minutes value of interval, if any.
`static long`
`monthsFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Returns months value of interval, if any.
`static long`
`nanosFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Returns nanoseconds value of interval, if any.
`static ValueInterval`
`parseFormattedInterval(IntervalQualifier qualifier, String s)`
Parses the specified string as `INTERVAL` value.
`static ValueInterval`
`parseInterval(IntervalQualifier qualifier, boolean negative, String s)`
Parses the specified string as `INTERVAL` value.
`static boolean`
`validateInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Ensures that all fields in interval are valid.
`static long`
`yearsFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)`
Returns years value of interval, if any.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### NANOS_PER_DAY_BI

public static final BigInteger NANOS_PER_DAY_BI
The number of nanoseconds per day as BigInteger.

## Method Details

### parseFormattedInterval

public static ValueInterval parseFormattedInterval(IntervalQualifier qualifier, String s)
Parses the specified string as `INTERVAL` value.

Parameters:
  `qualifier` - the default qualifier to use if string does not have one
  `s` - the string with type information to parse
Returns:
  the interval value. Type of value can be different from the specified qualifier.

### parseInterval

public static ValueInterval parseInterval(IntervalQualifier qualifier, boolean negative, String s)
Parses the specified string as `INTERVAL` value.

Parameters:
  `qualifier` - the qualifier of interval
  `negative` - whether the interval is negative
  `s` - the string to parse
Returns:
  the interval value

### appendInterval

public static StringBuilder appendInterval(StringBuilder buff, IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Formats interval as a string and appends it to a specified string builder.

Parameters:
  `buff` - string builder to append to
  `qualifier` - qualifier of the interval
  `negative` - whether interval is negative
  `leading` - the value of leading field
  `remaining` - the value of all remaining fields
Returns:
  the specified string builder

### intervalToAbsolute

public static BigInteger intervalToAbsolute(ValueInterval interval)
Converts interval value to an absolute value.

Parameters:
  `interval` - the interval value
Returns:
  absolute value in months for year-month intervals, in nanoseconds for day-time intervals

### intervalFromAbsolute

public static ValueInterval intervalFromAbsolute(IntervalQualifier qualifier, BigInteger absolute)
Converts absolute value to an interval value.

Parameters:
  `qualifier` - the qualifier of interval
  `absolute` - absolute value in months for year-month intervals, in nanoseconds for day-time intervals
Returns:
  the interval value

### validateInterval

public static boolean validateInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Ensures that all fields in interval are valid.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  fixed value of negative field

### yearsFromInterval

public static long yearsFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Returns years value of interval, if any.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  years, or 0

### monthsFromInterval

public static long monthsFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Returns months value of interval, if any.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  months, or 0

### daysFromInterval

public static long daysFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Returns days value of interval, if any.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  days, or 0

### hoursFromInterval

public static long hoursFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Returns hours value of interval, if any.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  hours, or 0

### minutesFromInterval

public static long minutesFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Returns minutes value of interval, if any.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  minutes, or 0

### nanosFromInterval

public static long nanosFromInterval(IntervalQualifier qualifier, boolean negative, long leading, long remaining)
Returns nanoseconds value of interval, if any.

Parameters:
  `qualifier` - qualifier
  `negative` - whether interval is negative
  `leading` - value of leading field
  `remaining` - values of all remaining fields
Returns:
  nanoseconds, or 0