Package org.h2.expression.function
Class DateTimeFunction
java.lang.Object
org.h2.expression.Expression
org.h2.expression.Operation1_2
org.h2.expression.function.Function1_2
org.h2.expression.function.DateTimeFunction
- All Implemented Interfaces:
NamedExpression
,HasSQL
,Typed
A date-time function.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final BigDecimal
private static final BigDecimal
private static final BigInteger
static final int
Century.static final int
DATE_TRUNC() (non-standard).static final int
DATEADD() (non-standard).static final int
DATEDIFF() (non-standard).static final int
Day of month.static final int
Day of week (locale-specific).static final int
Day of year.static final int
Decade.static final int
Day of week (locale-specific) for PostgreSQL compatibility.static final int
Epoch.static final int
EXTRACT().private final int
private static final String[]
private static final int
private final int
static final int
Hour.static final int
ISO day of week.static final int
ISO week.static final int
ISO week-based year.static final int
Microsecond.static final int
Millennium.static final int
Millisecond.static final int
Minute.static final int
Month.private static final String[]
static final int
Nanosecond.static final int
Quarter.static final int
Second.static final int
Time zone hour.static final int
Time zone minute.static final int
Time zone second.static final int
Week (locale-specific).private static WeekFields
Local definitions of day-of-week, week-of-month, and week-of-year.static final int
Week-based year (locale-specific).static final int
Year.Fields inherited from class org.h2.expression.Operation1_2
left, right, type
Fields inherited from class org.h2.expression.Expression
AUTO_PARENTHESES, MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL, WITH_PARENTHESES, WITHOUT_PARENTHESES
Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Value
addToTimeZone
(int field, long count, Value v, int type, long dateValue, long timeNanos) private static Value
addYearsMonths
(int field, boolean years, long count, Value v, int type, long dateValue, long timeNanos) private static int
century
(int year) static Value
dateadd
(SessionLocal session, int field, long count, Value v) DATEADD function.private static long
datediff
(SessionLocal session, int field, Value v1, Value v2) Calculate the number of crossed unit boundaries between two timestamps.private static int
decade
(int year) (package private) static int
extractDateTime
(SessionLocal session, Value date, int field) private static ValueNumeric
extractEpoch
(SessionLocal session, Value value) private static int
extractInteger
(SessionLocal session, Value date, int field) Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.private static int
extractInterval
(Value date, int field) static int
Get date-time field for the specified name.static String
getFieldName
(int field) Get the name of the specified date-time field.private static int
getLocalDayOfWeek
(long dateValue) private static int
getLocalWeekOfYear
(long dateValue) getName()
Get the name.getUnenclosedSQL
(StringBuilder builder, int sqlFlags) Get the SQL statement of this expression.getValue
(SessionLocal session, Value v1, Value v2) Returns the value of this function.private static WeekFields
private static int
millennium
(int year) optimize
(SessionLocal session) Try to optimize the expression.private static Value
truncateDate
(SessionLocal session, int field, Value value) Truncate the given date-time value to the specified field.private static long
truncateToWeek
(long dateValue, int firstDayOfWeek) private static long
truncateToWeekYear
(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek) private static long
weekdiff
(long absolute1, long absolute2, int firstDayOfWeek) Methods inherited from class org.h2.expression.function.Function1_2
getValue
Methods inherited from class org.h2.expression.Operation1_2
getCost, getSubexpression, getSubexpressionCount, getType, isEverything, mapColumns, setEvaluatable, updateAggregate
Methods inherited from class org.h2.expression.Expression
addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getColumnNameForView, getEnclosedSQL, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSQL, getSQL, getSQL, getTableAlias, getTableName, getWhenSQL, getWhenValue, isConstant, isIdentity, isNullConstant, isValueSet, isWhenConditionOperand, needParentheses, optimizeCondition, toString, writeExpressions, writeExpressions
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
Field Details
-
EXTRACT
public static final int EXTRACTEXTRACT().- See Also:
-
DATE_TRUNC
public static final int DATE_TRUNCDATE_TRUNC() (non-standard).- See Also:
-
DATEADD
public static final int DATEADDDATEADD() (non-standard).- See Also:
-
DATEDIFF
public static final int DATEDIFFDATEDIFF() (non-standard).- See Also:
-
NAMES
-
YEAR
public static final int YEARYear.- See Also:
-
MONTH
public static final int MONTHMonth.- See Also:
-
DAY
public static final int DAYDay of month.- See Also:
-
HOUR
public static final int HOURHour.- See Also:
-
MINUTE
public static final int MINUTEMinute.- See Also:
-
SECOND
public static final int SECONDSecond.- See Also:
-
TIMEZONE_HOUR
public static final int TIMEZONE_HOURTime zone hour.- See Also:
-
TIMEZONE_MINUTE
public static final int TIMEZONE_MINUTETime zone minute.- See Also:
-
TIMEZONE_SECOND
public static final int TIMEZONE_SECONDTime zone second.- See Also:
-
MILLENNIUM
public static final int MILLENNIUMMillennium.- See Also:
-
CENTURY
public static final int CENTURYCentury.- See Also:
-
DECADE
public static final int DECADEDecade.- See Also:
-
QUARTER
public static final int QUARTERQuarter.- See Also:
-
MILLISECOND
public static final int MILLISECONDMillisecond.- See Also:
-
MICROSECOND
public static final int MICROSECONDMicrosecond.- See Also:
-
NANOSECOND
public static final int NANOSECONDNanosecond.- See Also:
-
DAY_OF_YEAR
public static final int DAY_OF_YEARDay of year.- See Also:
-
ISO_DAY_OF_WEEK
public static final int ISO_DAY_OF_WEEKISO day of week.- See Also:
-
ISO_WEEK
public static final int ISO_WEEKISO week.- See Also:
-
ISO_WEEK_YEAR
public static final int ISO_WEEK_YEARISO week-based year.- See Also:
-
DAY_OF_WEEK
public static final int DAY_OF_WEEKDay of week (locale-specific).- See Also:
-
WEEK
public static final int WEEKWeek (locale-specific).- See Also:
-
WEEK_YEAR
public static final int WEEK_YEARWeek-based year (locale-specific).- See Also:
-
EPOCH
public static final int EPOCHEpoch.- See Also:
-
DOW
public static final int DOWDay of week (locale-specific) for PostgreSQL compatibility.- See Also:
-
FIELDS_COUNT
private static final int FIELDS_COUNT- See Also:
-
FIELD_NAMES
-
BD_SECONDS_PER_DAY
-
BI_SECONDS_PER_DAY
-
BD_NANOS_PER_SECOND
-
WEEK_FIELDS
Local definitions of day-of-week, week-of-month, and week-of-year. -
function
private final int function -
field
private final int field
-
-
Constructor Details
-
DateTimeFunction
-
-
Method Details
-
getField
Get date-time field for the specified name.- Parameters:
name
- the name- Returns:
- the date-time field
- Throws:
DbException
- on unknown field name
-
getFieldName
Get the name of the specified date-time field.- Parameters:
field
- the date-time field- Returns:
- the name of the specified field
-
getValue
Description copied from class:Function1_2
Returns the value of this function.- Overrides:
getValue
in classFunction1_2
- Parameters:
session
- the sessionv1
- the value of first argumentv2
- the value of second argument, ornull
- Returns:
- the resulting value
-
extractInteger
Get the specified field of a date, however with years normalized to positive or negative, and month starting with 1.- Parameters:
session
- the sessiondate
- the date valuefield
- the field type- Returns:
- the value
-
extractInterval
-
extractDateTime
-
truncateDate
Truncate the given date-time value to the specified field.- Parameters:
session
- the sessionfield
- the date-time fieldvalue
- the date-time value- Returns:
- date the truncated value
-
truncateToWeek
private static long truncateToWeek(long dateValue, int firstDayOfWeek) -
truncateToWeekYear
private static long truncateToWeekYear(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek) -
dateadd
DATEADD function.- Parameters:
session
- the sessionfield
- the date-time fieldcount
- count to addv
- value to add to- Returns:
- result
-
addYearsMonths
-
addToTimeZone
-
datediff
Calculate the number of crossed unit boundaries between two timestamps. This method is supported for MS SQL Server compatibility.DATEDIFF(YEAR, '2004-12-31', '2005-01-01') = 1
- Parameters:
session
- the sessionfield
- the date-time fieldv1
- the first date-time valuev2
- the second date-time value- Returns:
- the number of crossed boundaries
-
weekdiff
private static long weekdiff(long absolute1, long absolute2, int firstDayOfWeek) -
millennium
private static int millennium(int year) -
century
private static int century(int year) -
decade
private static int decade(int year) -
getLocalDayOfWeek
private static int getLocalDayOfWeek(long dateValue) -
getLocalWeekOfYear
private static int getLocalWeekOfYear(long dateValue) -
getWeekFields
-
extractEpoch
-
optimize
Description copied from class:Expression
Try to optimize the expression.- Specified by:
optimize
in classExpression
- Parameters:
session
- the session- Returns:
- the optimized expression
-
getUnenclosedSQL
Description copied from class:Expression
Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.- Overrides:
getUnenclosedSQL
in classFunction1_2
- Parameters:
builder
- string buildersqlFlags
- formatting flags- Returns:
- the specified string builder
-
getName
Description copied from interface:NamedExpression
Get the name.- Returns:
- the name in uppercase
-