Package org.h2.util

Class IntervalUtils


  • public class IntervalUtils
    extends java.lang.Object
    This utility class contains interval conversion functions.
    • Field Detail

      • NANOS_PER_SECOND_BI

        private static final java.math.BigInteger NANOS_PER_SECOND_BI
      • NANOS_PER_MINUTE_BI

        private static final java.math.BigInteger NANOS_PER_MINUTE_BI
      • NANOS_PER_HOUR_BI

        private static final java.math.BigInteger NANOS_PER_HOUR_BI
      • NANOS_PER_DAY_BI

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

        private static final java.math.BigInteger MONTHS_PER_YEAR_BI
      • HOURS_PER_DAY_BI

        private static final java.math.BigInteger HOURS_PER_DAY_BI
      • MINUTES_PER_DAY_BI

        private static final java.math.BigInteger MINUTES_PER_DAY_BI
      • MINUTES_PER_HOUR_BI

        private static final java.math.BigInteger MINUTES_PER_HOUR_BI
      • LEADING_MIN

        private static final java.math.BigInteger LEADING_MIN
      • LEADING_MAX

        private static final java.math.BigInteger LEADING_MAX
    • Constructor Detail

      • IntervalUtils

        private IntervalUtils()
    • Method Detail

      • parseFormattedInterval

        public static ValueInterval parseFormattedInterval​(IntervalQualifier qualifier,
                                                           java.lang.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​(java.lang.String s,
                                  int i)
      • skipWSEnd

        private static int skipWSEnd​(java.lang.String s,
                                     int i)
      • parseInterval

        public static ValueInterval parseInterval​(IntervalQualifier qualifier,
                                                  boolean negative,
                                                  java.lang.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,
                                                    java.lang.String s,
                                                    char ch,
                                                    int max,
                                                    boolean negative)
      • parseIntervalLeading

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

        private static long parseIntervalRemaining​(java.lang.String s,
                                                   int start,
                                                   int end,
                                                   int max)
      • parseIntervalRemainingSeconds

        private static long parseIntervalRemainingSeconds​(java.lang.String s,
                                                          int start)
      • appendInterval

        public static java.lang.StringBuilder appendInterval​(java.lang.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 java.math.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 java.math.BigInteger intervalToAbsolute​(ValueInterval interval,
                                                               java.math.BigInteger multiplier,
                                                               java.math.BigInteger totalMultiplier)
      • intervalToAbsolute

        private static java.math.BigInteger intervalToAbsolute​(ValueInterval interval,
                                                               java.math.BigInteger multiplier)
      • intervalFromAbsolute

        public static ValueInterval intervalFromAbsolute​(IntervalQualifier qualifier,
                                                         java.math.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,
                                                          java.math.BigInteger absolute,
                                                          java.math.BigInteger divisor)
      • leadingExact

        private static long leadingExact​(java.math.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