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 Details

    • NANOS_PER_SECOND_BI

      private static final BigInteger NANOS_PER_SECOND_BI
    • NANOS_PER_MINUTE_BI

      private static final BigInteger NANOS_PER_MINUTE_BI
    • NANOS_PER_HOUR_BI

      private static final BigInteger NANOS_PER_HOUR_BI
    • NANOS_PER_DAY_BI

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

      private static final BigInteger MONTHS_PER_YEAR_BI
    • HOURS_PER_DAY_BI

      private static final BigInteger HOURS_PER_DAY_BI
    • MINUTES_PER_DAY_BI

      private static final BigInteger MINUTES_PER_DAY_BI
    • MINUTES_PER_HOUR_BI

      private static final BigInteger MINUTES_PER_HOUR_BI
    • LEADING_MIN

      private static final BigInteger LEADING_MIN
    • LEADING_MAX

      private static final BigInteger LEADING_MAX
  • Constructor Details

    • IntervalUtils

      private IntervalUtils()
  • 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.
    • skipWS

      private static int skipWS(String s, int i)
    • skipWSEnd

      private static int skipWSEnd(String s, int i)
    • 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
    • parseInterval2

      private static ValueInterval parseInterval2(IntervalQualifier qualifier, String s, char ch, int max, boolean negative)
    • parseIntervalLeading

      private static long parseIntervalLeading(String s, int start, int end, boolean negative)
    • parseIntervalRemaining

      private static long parseIntervalRemaining(String s, int start, int end, int max)
    • parseIntervalRemainingSeconds

      private static long parseIntervalRemainingSeconds(String s, int start)
    • 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
    • intervalToAbsolute

      private static BigInteger intervalToAbsolute(ValueInterval interval, BigInteger multiplier, BigInteger totalMultiplier)
    • intervalToAbsolute

      private static BigInteger intervalToAbsolute(ValueInterval interval, BigInteger multiplier)
    • 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
    • intervalFromAbsolute

      private static ValueInterval intervalFromAbsolute(IntervalQualifier qualifier, BigInteger absolute, BigInteger divisor)
    • leadingExact

      private static long leadingExact(BigInteger absolute)
    • 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