Module org.jooq

Class YearToSecond

  • All Implemented Interfaces:
    Serializable, Comparable<YearToSecond>, Interval

    public final class YearToSecond
    extends Number
    implements Interval, Comparable<YearToSecond>
    A combined YearToMonth / DayToSecond interval.

    Some databases (e.g. PostgreSQL) allow for mixing YEAR TO MONTH and DAY TO SECOND intervals, despite the many questions such a combination raises. The YearToSecond 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), the YearToMonth 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


    • P11M has 330 days
    • P1Y-1M has 330 days
    • P1Y has 365.25 days
    • P1Y1M has 396.25 days
    Lukas Eder
    See Also:
    Serialized Form
    • Method Detail

      • valueOf

        public static YearToSecond valueOf​(double milli)
        Load a Double representation of a INTERVAL YEAR TO SECOND by assuming standard 24 hour days and 60 second minutes.
        milli - The number of milliseconds as a fractional number
        The loaded INTERVAL DAY TO SECOND object
      • toDuration

        public final Duration toDuration()
        Description copied from interface: Interval
        Get a duration representation of this interval.

        There is an obvious Duration representation for DayToSecond intervals. If the interval contains YearMonth 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 interface Interval
      • valueOf

        public static YearToSecond valueOf​(String string)
        Parse a string representation of a INTERVAL YEAR TO SECOND
        string - A string representation of the form [+|-][years]-[months] [+|-][days] [hours]:[minutes]:[seconds].[fractional seconds]
        The parsed YEAR TO SECOND object, or null if the string could not be parsed.
      • neg

        public final YearToSecond neg()
        Description copied from interface: Interval
        Negate the interval (change its sign)
        Specified by:
        neg in interface Interval
      • abs

        public final YearToSecond abs()
        Description copied from interface: Interval
        Get the absolute value of the interval (set its sign to positive)
        Specified by:
        abs in interface Interval
      • 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
        Specified by:
        getSign in interface Interval
        1 for positive or zero, -1 for negative
      • hashCode

        public int hashCode()
        hashCode in class Object