Top Description Fields Constructors Methods
org.hibernate.query.sqm

public final Enum TemporalUnit

extends Enum<TemporalUnit>
Class Inheritance
Imports
org.hibernate.dialect.Dialect, org.hibernate.query.SemanticException

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.

Author
Gavin King
See Also
Dialect#extractPattern(TemporalUnit)

Field Summary

Modifier and TypeField and Description
public static final TemporalUnit
DATE

The date part of a timestamp, datetime, or offset datetime, as a java.time.LocalDate.

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().

public static final TemporalUnit
DAY_OF_MONTH

The calendar day of the month, a synonym for DAY.

public static final TemporalUnit
DAY_OF_WEEK

The day of the week, from 1 (Sunday) to 7 (Saturday).

public static final TemporalUnit
DAY_OF_YEAR

The day of the year, counting from 1.

public static final TemporalUnit
EPOCH

An internal value representing the Unix epoch, the elapsed seconds since January 1, 1970.

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().

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().

public static final TemporalUnit
MONTH

Calendar month.

public static final TemporalUnit
NANOSECOND

Nanosecond, the basic most granular unit of duration.

public static final TemporalUnit
NATIVE

An internal value representing the "native" resolution for date/time arithmetic of the underlying platform.

public static final TemporalUnit
OFFSET

The timezone offset of an offset datetime, as a java.time.ZoneOffset.

public static final TemporalUnit
QUARTER

Quarter, defined to mean three months.

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().

public static final TemporalUnit
TIME

The time part of a timestamp, datetime, or offset datetime, as a java.time.LocalTime.

public static final TemporalUnit
TIMEZONE_HOUR

The hour field of the OFFSET in an offset datetime.

public static final TemporalUnit
TIMEZONE_MINUTE

The minute field of the OFFSET in an offset datetime.

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().

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.

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.

public static final TemporalUnit
YEAR

Calendar year.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
public String
private static String

Returns:

a string to inject into the SQL expression
factorAsString
(long
the conversion factor
factor
)

Obtain a fragment of SQL that can be used to perform a unit conversion.

public boolean
isDateUnit()

Is this unit extractable from a date?

public boolean
isTimeUnit()

Is this unit extractable from a time?

private long
normalizationFactor(Dialect dialect)

The conversion factor required to convert this unit to its normalized() unit.

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.

public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static TemporalUnit
public static TemporalUnit[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

DATEback to summary
public static final TemporalUnit DATE

The date part of a timestamp, datetime, or offset datetime, as a java.time.LocalDate.

DAYback to summary
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().

DAY_OF_MONTHback to summary
public static final TemporalUnit DAY_OF_MONTH

The calendar day of the month, a synonym for DAY.

DAY_OF_WEEKback to summary
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_YEARback to summary
public static final TemporalUnit DAY_OF_YEAR

The day of the year, counting from 1.

Not supported by every database platform.

EPOCHback to summary
public static final TemporalUnit EPOCH

An internal value representing the Unix epoch, the elapsed seconds since January 1, 1970.

HOURback to summary
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().

MINUTEback to summary
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().

MONTHback to summary
public static final TemporalUnit MONTH

Calendar month.

NANOSECONDback to summary
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
NATIVEback to summary
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()
OFFSETback to summary
public static final TemporalUnit OFFSET

The timezone offset of an offset datetime, as a java.time.ZoneOffset.

QUARTERback to summary
public static final TemporalUnit QUARTER

Quarter, defined to mean three months.

SECONDback to summary
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).

TIMEback to summary
public static final TemporalUnit TIME

The time part of a timestamp, datetime, or offset datetime, as a java.time.LocalTime.

TIMEZONE_HOURback to summary
public static final TemporalUnit TIMEZONE_HOUR

The hour field of the OFFSET in an offset datetime.

TIMEZONE_MINUTEback to summary
public static final TemporalUnit TIMEZONE_MINUTE

The minute field of the OFFSET in an offset datetime.

WEEKback to summary
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.

WEEK_OF_MONTHback to summary
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_YEARback to summary
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.

YEARback to summary
public static final TemporalUnit YEAR

Calendar year.

Constructor Detail

TemporalUnitback to summary
private TemporalUnit()

Method Detail

conversionFactorback to summary
public String conversionFactor(TemporalUnit unit, Dialect dialect)
conversionFactorFullback to summary
public String conversionFactorFull(TemporalUnit unit, Dialect dialect)
factorAsStringback to summary
private static String factorAsString(long factor)

Obtain a fragment of SQL that can be used to perform a unit conversion. If the normalization factor is very large, represent it using exponential form so as to minimize the noise the generated SQL.

Parameters
factor:long

the conversion factor

Returns:String

a string to inject into the SQL expression

isDateUnitback to summary
public boolean isDateUnit()

Is this unit extractable from a date?

isTimeUnitback to summary
public boolean isTimeUnit()

Is this unit extractable from a time?

normalizationFactorback to summary
private long normalizationFactor(Dialect dialect)

The conversion factor required to convert this unit to its normalized() unit.

normalizedback to summary
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.

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static TemporalUnit valueOf(String name)
valuesback to summary
public static TemporalUnit[] values()