Enum Class TemporalUnit

java.lang.Object
java.lang.Enum<TemporalUnit>
org.hibernate.query.common.TemporalUnit
All Implemented Interfaces:
Serializable, Comparable<TemporalUnit>, Constable

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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    The date part of a timestamp, datetime, or offset datetime, as a LocalDate.
    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().
    The calendar day of the month, a synonym for DAY.
    The day of the week, from 1 (Sunday) to 7 (Saturday).
    The day of the year, counting from 1.
    An internal value representing the Unix epoch, the elapsed seconds since January 1, 1970.
    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, 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().
    Calendar month.
    Nanosecond, the basic most granular unit of duration.
    An internal value representing the "native" resolution for date/time arithmetic of the underlying platform.
    The timezone offset of an offset datetime, as a ZoneOffset.
    Quarter, defined to mean three months.
    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 time part of a timestamp, datetime, or offset datetime, as a LocalTime.
    The hour field of the OFFSET in an offset datetime.
    The minute field of the OFFSET in an offset datetime.
    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().
    The week of the month, where the first day of the month is in week 1, and a new week starts each Sunday.
    The week of the year, where the first day of the year is in week 1, and a new week starts each Sunday.
    Calendar year.
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    boolean
    Is this unit extractable from a date?
    boolean
    Is this unit extractable from a time?
    The unit that this unit "normalizes to", either NANOSECOND or MONTH, which represent the two basic types of duration: "physical" durations, and "calendar" durations.
     
    Returns the enum constant of this class with the specified name.
    static TemporalUnit[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • 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:
    • 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.

    • OFFSET

      public static final TemporalUnit OFFSET
      The timezone offset of an offset datetime, as a ZoneOffset.
    • 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:
  • Method Details

    • values

      public static TemporalUnit[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TemporalUnit valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • conversionFactor

      public String conversionFactor(TemporalUnit unit, Dialect dialect)
    • conversionFactorFull

      public String conversionFactorFull(TemporalUnit unit, Dialect dialect)
    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Enum<TemporalUnit>