Class DayToSecond

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<DayToSecond>, Interval

    public final class DayToSecond
    extends java.lang.Number
    implements Interval, java.lang.Comparable<DayToSecond>
    An implementation for the SQL standard INTERVAL DAY TO SECOND data type.

    DayToSecond is a Number whose Number.intValue() represents the (truncated) number of milliseconds of the interval, Number.doubleValue() represents the approximative number of milliseconds (including hours, minutes, seconds, nanoseconds) of the interval.

    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) and Field.sub(Field) Databases that have been observed to natively support INTERVAL data types are:

    These dialects have been observed to partially support INTERVAL data types in date time arithmetic functions, such as TIMESTAMPADD, and TIMESTAMPDIFF:

    Author:
    Lukas Eder
    See Also:
    Interval, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DayToSecond()
      Create a new interval.
      DayToSecond​(int days)
      Create a new day interval.
      DayToSecond​(int days, int hours)
      Create a new day-hour interval.
      DayToSecond​(int days, int hours, int minutes)
      Create a new day-minute interval.
      DayToSecond​(int days, int hours, int minutes, int seconds)
      Create a new day-second interval.
      DayToSecond​(int days, int hours, int minutes, int seconds, int nano)
      Create a new day-nanoseconds interval.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DayToSecond abs()
      Get the absolute value of the interval (set its sign to positive)
      int compareTo​(DayToSecond that)  
      double doubleValue()  
      boolean equals​(java.lang.Object obj)  
      float floatValue()  
      int getDays()
      Get the day-part of this interval
      int getHours()
      Get the hour-part of this interval
      int getMicro()
      Get the (truncated) micro-part of this interval
      int getMilli()
      Get the (truncated) milli-part of this interval
      int getMinutes()
      Get the minute-part of this interval
      int getNano()
      Get the nano-part of this interval
      int getSeconds()
      Get the second-part of this interval
      int getSign()
      The sign of the interval
      double getTotalDays()
      Get the whole interval in days
      double getTotalHours()
      Get the whole interval in hours
      double getTotalMicro()
      Get the whole interval in micro-seconds
      double getTotalMilli()
      Get the whole interval in milli-seconds
      double getTotalMinutes()
      Get the whole interval in minutes
      double getTotalNano()
      Get the whole interval in nano-seconds
      double getTotalSeconds()
      Get the whole interval in seconds
      int hashCode()  
      int intValue()  
      long longValue()  
      DayToSecond neg()
      Negate the interval (change its sign)
      java.time.Duration toDuration()
      Get a duration representation of this interval.
      java.lang.String toString()  
      static DayToSecond valueOf​(double milli)
      Load a Double representation of a INTERVAL DAY TO SECOND by assuming standard 24 hour days and 60 second minutes.
      static DayToSecond valueOf​(long second, int nanos)
      Load a Double representation of a INTERVAL DAY TO SECOND by assuming standard 24 hour days and 60 second minutes.
      static DayToSecond valueOf​(java.lang.String string)
      Parse a string representation of a INTERVAL DAY TO SECOND
      static DayToSecond valueOf​(java.time.Duration duration)
      Transform a Duration into a DayToSecond interval by taking its number of milliseconds.
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DayToSecond

        public DayToSecond()
        Create a new interval.
      • DayToSecond

        public DayToSecond​(int days)
        Create a new day interval.
      • DayToSecond

        public DayToSecond​(int days,
                           int hours)
        Create a new day-hour interval.
      • DayToSecond

        public DayToSecond​(int days,
                           int hours,
                           int minutes)
        Create a new day-minute interval.
      • DayToSecond

        public DayToSecond​(int days,
                           int hours,
                           int minutes,
                           int seconds)
        Create a new day-second interval.
      • DayToSecond

        public DayToSecond​(int days,
                           int hours,
                           int minutes,
                           int seconds,
                           int nano)
        Create a new day-nanoseconds interval.
    • Method Detail

      • valueOf

        public static DayToSecond valueOf​(java.lang.String string)
        Parse a string representation of a INTERVAL DAY TO SECOND
        Parameters:
        string - A string representation of the form [+|-][days] [hours]:[minutes]:[seconds].[fractional seconds]
        Returns:
        The parsed INTERVAL DAY TO SECOND object, or null if the string could not be parsed.
      • valueOf

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

        public static DayToSecond valueOf​(long second,
                                          int nanos)
        Load a Double representation of a INTERVAL DAY TO SECOND by assuming standard 24 hour days and 60 second minutes.
        Parameters:
        second - The number of seconds
        nanos - The number of nano seconds
        Returns:
        The loaded INTERVAL DAY TO SECOND object
      • valueOf

        public static DayToSecond valueOf​(java.time.Duration duration)
        Transform a Duration into a DayToSecond interval by taking its number of milliseconds.
      • toDuration

        public final java.time.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
      • intValue

        public final int intValue()
        Specified by:
        intValue in interface Interval
        Specified by:
        intValue in class java.lang.Number
        See Also:
        Number.intValue()
      • longValue

        public final long longValue()
        Specified by:
        longValue in interface Interval
        Specified by:
        longValue in class java.lang.Number
        See Also:
        Number.longValue()
      • floatValue

        public final float floatValue()
        Specified by:
        floatValue in interface Interval
        Specified by:
        floatValue in class java.lang.Number
        See Also:
        Number.floatValue()
      • doubleValue

        public final double doubleValue()
        Specified by:
        doubleValue in interface Interval
        Specified by:
        doubleValue in class java.lang.Number
        See Also:
        Number.doubleValue()
      • neg

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

        public final DayToSecond abs()
        Description copied from interface: Interval
        Get the absolute value of the interval (set its sign to positive)
        Specified by:
        abs in interface Interval
      • 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
      • getTotalDays

        public final double getTotalDays()
        Get the whole interval in days
      • getTotalHours

        public final double getTotalHours()
        Get the whole interval in hours
      • getTotalMinutes

        public final double getTotalMinutes()
        Get the whole interval in minutes
      • getTotalSeconds

        public final double getTotalSeconds()
        Get the whole interval in seconds
      • getTotalMilli

        public final double getTotalMilli()
        Get the whole interval in milli-seconds
      • getTotalMicro

        public final double getTotalMicro()
        Get the whole interval in micro-seconds
      • getTotalNano

        public final double getTotalNano()
        Get the whole interval in nano-seconds
      • getSign

        public final int getSign()
        Description copied from interface: Interval
        The sign of the interval
        Specified by:
        getSign in interface Interval
        Returns:
        1 for positive or zero, -1 for negative
      • compareTo

        public final int compareTo​(DayToSecond that)
        Specified by:
        compareTo in interface java.lang.Comparable<DayToSecond>
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object