Enum TemporalUnit
- java.lang.Object
-
- java.lang.Enum<TemporalUnit>
-
- org.hibernate.query.sqm.TemporalUnit
-
- All Implemented Interfaces:
Serializable
,Comparable<TemporalUnit>
public enum TemporalUnit extends Enum<TemporalUnit>
A temporal field type which can occur as an argument toextract()
or as the unit of a duration expression. A temporal field type may also occur as an argument totimestampadd()
ortimestampdiff()
, 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
, andNANOSECOND
.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 aLocalDate
.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 toextract()
.DAY_OF_MONTH
The calendar day of the month, a synonym forDAY
.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 toextract()
.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 toextract()
.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 aZoneOffset
.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 toextract()
.TIME
The time part of a timestamp, datetime, or offset datetime, as aLocalTime
.TIMEZONE_HOUR
The hour field of theOFFSET
in an offset datetime.TIMEZONE_MINUTE
The minute field of theOFFSET
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 toextract()
.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
conversionFactor(TemporalUnit unit, Dialect dialect)
boolean
isDateUnit()
Is this unit extractable from a date?boolean
isTimeUnit()
Is this unit extractable from a time?TemporalUnit
normalized()
The unit that this unit "normalizes to", eitherNANOSECOND
orMONTH
, which represent the two basic types of duration: "physical" durations, and "calendar" durations.String
toString()
static TemporalUnit
valueOf(String name)
Returns the enum constant of this type with the specified name.static TemporalUnit[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
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 toextract()
. This is different toWEEK_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 toextract()
.
-
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 toextract()
.
-
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 toextract()
.
-
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 toextract()
. 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'sDuration
type does. When it occurs as an argument toextract()
, 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 forDAY
.
-
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 toWEEK
.Supported on all platforms which natively support
DAY_OF_WEEK
andDAY_OF_YEAR
.
-
OFFSET
public static final TemporalUnit OFFSET
The timezone offset of an offset datetime, as aZoneOffset
.
-
TIMEZONE_HOUR
public static final TemporalUnit TIMEZONE_HOUR
The hour field of theOFFSET
in an offset datetime.
-
TIMEZONE_MINUTE
public static final TemporalUnit TIMEZONE_MINUTE
The minute field of theOFFSET
in an offset datetime.
-
DATE
public static final TemporalUnit DATE
The date part of a timestamp, datetime, or offset datetime, as aLocalDate
.
-
TIME
public static final TemporalUnit TIME
The time part of a timestamp, datetime, or offset datetime, as aLocalTime
.
-
EPOCH
public static final TemporalUnit EPOCH
An internal value representing the Unix epoch, the elapsed seconds since January 1, 1970. Currently not supported in HQL.
-
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 betweenNANOSECOND
s and a unit that the database understands. On some platforms this is also used to avoid numeric overflow.
-
-
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 nameNullPointerException
- if the argument is null
-
conversionFactor
public String conversionFactor(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", eitherNANOSECOND
orMONTH
, which represent the two basic types of duration: "physical" durations, and "calendar" durations.
-
toString
public String toString()
- Overrides:
toString
in classEnum<TemporalUnit>
-
-