Enum TemporalUnit

  • All Implemented Interfaces:
    Serializable, Comparable<TemporalUnit>

    public enum TemporalUnit
    extends Enum<TemporalUnit>
    A temporal field type which can occur as an argument to extract() or as the unit of a duration expression. A temporal field type may also occur as an argument to timestampadd() or timestampdiff(), in which case it is interpreted as a unit of duration.

    Note that not every TemporalUnit is legal duration unit. The units of a duration are: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEK, QUARTER, and NANOSECOND.

    Further note that accepted unit types in extract() vary according to the type of the second argument (date, time, or timestamp), and according to capabilities of the database platform.

    See Also:
    Dialect.extractPattern(TemporalUnit)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      DATE
      The date part of a timestamp, datetime, or offset datetime, as a LocalDate.
      DAY
      Day, defined to mean 24 hours when it occurs as a unit of duration, or to mean the calendar day of the month when passed to extract().
      DAY_OF_MONTH
      The calendar day of the month, a synonym for DAY.
      DAY_OF_WEEK
      The day of the week, from 1 (Sunday) to 7 (Saturday).
      DAY_OF_YEAR
      The day of the year, counting from 1.
      EPOCH
      An internal value representing the Unix epoch, the elapsed seconds since January 1, 1970.
      HOUR
      Hour, defined to mean 60 minutes when it occurs as a unit of duration, or to mean the hour field in the range 0-23 (regular 24-hour time) when passed to extract().
      MINUTE
      Minute, defined to mean 60 seconds when it occurs as a unit of duration, or to mean the minute field in the range 0-59 when passed to extract().
      MONTH
      Calendar month.
      NANOSECOND
      Nanosecond, the basic most granular unit of duration.
      NATIVE
      An internal value representing the "native" resolution for date/time arithmetic of the underlying platform.
      OFFSET
      The timezone offset of an offset datetime, as a ZoneOffset.
      QUARTER
      Quarter, defined to mean three months.
      SECOND
      Second, defined to mean 1000 nanoseconds when it occurs as a unit of duration, or to mean the second field in the range 0-59 when passed to extract().
      TIME
      The time part of a timestamp, datetime, or offset datetime, as a LocalTime.
      TIMEZONE_HOUR
      The hour field of the OFFSET in an offset datetime.
      TIMEZONE_MINUTE
      The minute field of the OFFSET in an offset datetime.
      WEEK
      Week, defined to mean 7 days when it occurs as a unit of duration, or to mean the ISO ISO-8601 week number when passed to extract().
      WEEK_OF_MONTH
      The week of the month, where the first day of the month is in week 1, and a new week starts each Sunday.
      WEEK_OF_YEAR
      The week of the year, where the first day of the year is in week 1, and a new week starts each Sunday.
      YEAR
      Calendar year.
    • Enum Constant Detail

      • YEAR

        public static final TemporalUnit YEAR
        Calendar year.
      • QUARTER

        public static final TemporalUnit QUARTER
        Quarter, defined to mean three months.
      • MONTH

        public static final TemporalUnit MONTH
        Calendar month.
      • WEEK

        public static final TemporalUnit WEEK
        Week, defined to mean 7 days when it occurs as a unit of duration, or to mean the ISO ISO-8601 week number when passed to extract(). This is different to WEEK_OF_YEAR.
      • DAY

        public static final TemporalUnit DAY
        Day, defined to mean 24 hours when it occurs as a unit of duration, or to mean the calendar day of the month when passed to extract().
      • HOUR

        public static final TemporalUnit HOUR
        Hour, defined to mean 60 minutes when it occurs as a unit of duration, or to mean the hour field in the range 0-23 (regular 24-hour time) when passed to extract().
      • MINUTE

        public static final TemporalUnit MINUTE
        Minute, defined to mean 60 seconds when it occurs as a unit of duration, or to mean the minute field in the range 0-59 when passed to extract().
      • SECOND

        public static final TemporalUnit SECOND
        Second, defined to mean 1000 nanoseconds when it occurs as a unit of duration, or to mean the second field in the range 0-59 when passed to extract(). The second field includes fractional seconds (it is a floating point value).
      • NANOSECOND

        public static final TemporalUnit NANOSECOND
        Nanosecond, the basic most granular unit of duration. Few databases support billions-of-seconds, but Java's Duration type does. When it occurs as an argument to extract(), the nanosecond field is interpreted to include full seconds.

        Note that the actual minimum granularity of a datetime varies by database platform (usually milliseconds or microseconds) so support for nanoseconds is emulated.

        See Also:
        NATIVE
      • DAY_OF_WEEK

        public static final TemporalUnit DAY_OF_WEEK
        The day of the week, from 1 (Sunday) to 7 (Saturday).

        Not supported by every database platform.

      • DAY_OF_YEAR

        public static final TemporalUnit DAY_OF_YEAR
        The day of the year, counting from 1.

        Not supported by every database platform.

      • DAY_OF_MONTH

        public static final TemporalUnit DAY_OF_MONTH
        The calendar day of the month, a synonym for DAY.
      • WEEK_OF_MONTH

        public static final TemporalUnit WEEK_OF_MONTH
        The week of the month, where the first day of the month is in week 1, and a new week starts each Sunday.

        Supported on all platforms which natively support DAY_OF_WEEK.

      • WEEK_OF_YEAR

        public static final TemporalUnit WEEK_OF_YEAR
        The week of the year, where the first day of the year is in week 1, and a new week starts each Sunday. This is different to WEEK.

        Supported on all platforms which natively support DAY_OF_WEEK and DAY_OF_YEAR.

      • TIMEZONE_HOUR

        public static final TemporalUnit TIMEZONE_HOUR
        The hour field of the OFFSET in an offset datetime.
      • TIMEZONE_MINUTE

        public static final TemporalUnit TIMEZONE_MINUTE
        The minute field of the OFFSET in an offset datetime.
      • DATE

        public static final TemporalUnit DATE
        The date part of a timestamp, datetime, or offset datetime, as a LocalDate.
      • TIME

        public static final TemporalUnit TIME
        The time part of a timestamp, datetime, or offset datetime, as a LocalTime.
      • EPOCH

        public static final TemporalUnit EPOCH
        An internal value representing the Unix epoch, the elapsed seconds since January 1, 1970.
      • NATIVE

        public static final TemporalUnit NATIVE
        An internal value representing the "native" resolution for date/time arithmetic of the underlying platform. Usually the smallest unit of fractional seconds, either milliseconds or microseconds. We define this value in order to avoid repeatedly converting between NANOSECONDs and a unit that the database understands. On some platforms this is also used to avoid numeric overflow.
        See Also:
        Dialect.getFractionalSecondPrecisionInNanos()
    • Method Detail

      • values

        public static TemporalUnit[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (TemporalUnit c : TemporalUnit.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static TemporalUnit valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • isDateUnit

        public boolean isDateUnit()
        Is this unit extractable from a date?
      • isTimeUnit

        public boolean isTimeUnit()
        Is this unit extractable from a time?
      • normalized

        public TemporalUnit normalized()
        The unit that this unit "normalizes to", either NANOSECOND or MONTH, which represent the two basic types of duration: "physical" durations, and "calendar" durations.