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
public final class DateTimeFunction extends Function1_2
A date-time function.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.math.BigDecimalBD_NANOS_PER_SECONDprivate static java.math.BigDecimalBD_SECONDS_PER_DAYprivate static java.math.BigIntegerBI_SECONDS_PER_DAYstatic intCENTURYCentury.static intDATE_TRUNCDATE_TRUNC() (non-standard).static intDATEADDDATEADD() (non-standard).static intDATEDIFFDATEDIFF() (non-standard).static intDAYDay of month.static intDAY_OF_WEEKDay of week (locale-specific).static intDAY_OF_YEARDay of year.static intDECADEDecade.static intDOWDay of week (locale-specific) for PostgreSQL compatibility.static intEPOCHEpoch.static intEXTRACTEXTRACT().private intfieldprivate static java.lang.String[]FIELD_NAMESprivate static intFIELDS_COUNTprivate intfunctionstatic intHOURHour.static intISO_DAY_OF_WEEKISO day of week.static intISO_WEEKISO week.static intISO_WEEK_YEARISO week-based year.static intMICROSECONDMicrosecond.static intMILLENNIUMMillennium.static intMILLISECONDMillisecond.static intMINUTEMinute.static intMONTHMonth.private static java.lang.String[]NAMESstatic intNANOSECONDNanosecond.static intQUARTERQuarter.static intSECONDSecond.static intTIMEZONE_HOURTime zone hour.static intTIMEZONE_MINUTETime zone minute.static intTIMEZONE_SECONDTime zone second.static intWEEKWeek (locale-specific).private static java.time.temporal.WeekFieldsWEEK_FIELDSLocal definitions of day-of-week, week-of-month, and week-of-year.static intWEEK_YEARWeek-based year (locale-specific).static intYEARYear.-
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 Constructor Description DateTimeFunction(int function, int field, Expression arg1, Expression arg2)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static ValueaddToTimeZone(int field, long count, Value v, int type, long dateValue, long timeNanos)private static ValueaddYearsMonths(int field, boolean years, long count, Value v, int type, long dateValue, long timeNanos)private static intcentury(int year)static Valuedateadd(SessionLocal session, int field, long count, Value v)DATEADD function.private static longdatediff(SessionLocal session, int field, Value v1, Value v2)Calculate the number of crossed unit boundaries between two timestamps.private static intdecade(int year)(package private) static intextractDateTime(SessionLocal session, Value date, int field)private static ValueNumericextractEpoch(SessionLocal session, Value value)private static intextractInteger(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 intextractInterval(Value date, int field)static intgetField(java.lang.String name)Get date-time field for the specified name.static java.lang.StringgetFieldName(int field)Get the name of the specified date-time field.private static intgetLocalDayOfWeek(long dateValue)private static intgetLocalWeekOfYear(long dateValue)java.lang.StringgetName()Get the name.java.lang.StringBuildergetUnenclosedSQL(java.lang.StringBuilder builder, int sqlFlags)Get the SQL statement of this expression.ValuegetValue(SessionLocal session, Value v1, Value v2)Returns the value of this function.private static java.time.temporal.WeekFieldsgetWeekFields()private static intmillennium(int year)Expressionoptimize(SessionLocal session)Try to optimize the expression.private static ValuetruncateDate(SessionLocal session, int field, Value value)Truncate the given date-time value to the specified field.private static longtruncateToWeek(long dateValue, int firstDayOfWeek)private static longtruncateToWeekYear(long dateValue, int firstDayOfWeek, int minimalDaysInFirstWeek)private static longweekdiff(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 Detail
-
EXTRACT
public static final int EXTRACT
EXTRACT().- See Also:
- Constant Field Values
-
DATE_TRUNC
public static final int DATE_TRUNC
DATE_TRUNC() (non-standard).- See Also:
- Constant Field Values
-
DATEADD
public static final int DATEADD
DATEADD() (non-standard).- See Also:
- Constant Field Values
-
DATEDIFF
public static final int DATEDIFF
DATEDIFF() (non-standard).- See Also:
- Constant Field Values
-
NAMES
private static final java.lang.String[] NAMES
-
YEAR
public static final int YEAR
Year.- See Also:
- Constant Field Values
-
MONTH
public static final int MONTH
Month.- See Also:
- Constant Field Values
-
DAY
public static final int DAY
Day of month.- See Also:
- Constant Field Values
-
HOUR
public static final int HOUR
Hour.- See Also:
- Constant Field Values
-
MINUTE
public static final int MINUTE
Minute.- See Also:
- Constant Field Values
-
SECOND
public static final int SECOND
Second.- See Also:
- Constant Field Values
-
TIMEZONE_HOUR
public static final int TIMEZONE_HOUR
Time zone hour.- See Also:
- Constant Field Values
-
TIMEZONE_MINUTE
public static final int TIMEZONE_MINUTE
Time zone minute.- See Also:
- Constant Field Values
-
TIMEZONE_SECOND
public static final int TIMEZONE_SECOND
Time zone second.- See Also:
- Constant Field Values
-
MILLENNIUM
public static final int MILLENNIUM
Millennium.- See Also:
- Constant Field Values
-
CENTURY
public static final int CENTURY
Century.- See Also:
- Constant Field Values
-
DECADE
public static final int DECADE
Decade.- See Also:
- Constant Field Values
-
QUARTER
public static final int QUARTER
Quarter.- See Also:
- Constant Field Values
-
MILLISECOND
public static final int MILLISECOND
Millisecond.- See Also:
- Constant Field Values
-
MICROSECOND
public static final int MICROSECOND
Microsecond.- See Also:
- Constant Field Values
-
NANOSECOND
public static final int NANOSECOND
Nanosecond.- See Also:
- Constant Field Values
-
DAY_OF_YEAR
public static final int DAY_OF_YEAR
Day of year.- See Also:
- Constant Field Values
-
ISO_DAY_OF_WEEK
public static final int ISO_DAY_OF_WEEK
ISO day of week.- See Also:
- Constant Field Values
-
ISO_WEEK
public static final int ISO_WEEK
ISO week.- See Also:
- Constant Field Values
-
ISO_WEEK_YEAR
public static final int ISO_WEEK_YEAR
ISO week-based year.- See Also:
- Constant Field Values
-
DAY_OF_WEEK
public static final int DAY_OF_WEEK
Day of week (locale-specific).- See Also:
- Constant Field Values
-
WEEK
public static final int WEEK
Week (locale-specific).- See Also:
- Constant Field Values
-
WEEK_YEAR
public static final int WEEK_YEAR
Week-based year (locale-specific).- See Also:
- Constant Field Values
-
EPOCH
public static final int EPOCH
Epoch.- See Also:
- Constant Field Values
-
DOW
public static final int DOW
Day of week (locale-specific) for PostgreSQL compatibility.- See Also:
- Constant Field Values
-
FIELDS_COUNT
private static final int FIELDS_COUNT
- See Also:
- Constant Field Values
-
FIELD_NAMES
private static final java.lang.String[] FIELD_NAMES
-
BD_SECONDS_PER_DAY
private static final java.math.BigDecimal BD_SECONDS_PER_DAY
-
BI_SECONDS_PER_DAY
private static final java.math.BigInteger BI_SECONDS_PER_DAY
-
BD_NANOS_PER_SECOND
private static final java.math.BigDecimal BD_NANOS_PER_SECOND
-
WEEK_FIELDS
private static volatile java.time.temporal.WeekFields 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 Detail
-
DateTimeFunction
public DateTimeFunction(int function, int field, Expression arg1, Expression arg2)
-
-
Method Detail
-
getField
public static int getField(java.lang.String name)
Get date-time field for the specified name.- Parameters:
name- the name- Returns:
- the date-time field
- Throws:
DbException- on unknown field name
-
getFieldName
public static java.lang.String getFieldName(int field)
Get the name of the specified date-time field.- Parameters:
field- the date-time field- Returns:
- the name of the specified field
-
getValue
public Value getValue(SessionLocal session, Value v1, Value v2)
Description copied from class:Function1_2Returns the value of this function.- Overrides:
getValuein classFunction1_2- Parameters:
session- the sessionv1- the value of first argumentv2- the value of second argument, ornull- Returns:
- the resulting value
-
extractInteger
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.- Parameters:
session- the sessiondate- the date valuefield- the field type- Returns:
- the value
-
extractInterval
private static int extractInterval(Value date, int field)
-
extractDateTime
static int extractDateTime(SessionLocal session, Value date, int field)
-
truncateDate
private static Value truncateDate(SessionLocal session, int field, Value value)
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
public static Value dateadd(SessionLocal session, int field, long count, Value v)
DATEADD function.- Parameters:
session- the sessionfield- the date-time fieldcount- count to addv- value to add to- Returns:
- result
-
addYearsMonths
private static Value addYearsMonths(int field, boolean years, long count, Value v, int type, long dateValue, long timeNanos)
-
addToTimeZone
private static Value addToTimeZone(int field, long count, Value v, int type, long dateValue, long timeNanos)
-
datediff
private static long datediff(SessionLocal session, int field, Value v1, Value v2)
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
private static java.time.temporal.WeekFields getWeekFields()
-
extractEpoch
private static ValueNumeric extractEpoch(SessionLocal session, Value value)
-
optimize
public Expression optimize(SessionLocal session)
Description copied from class:ExpressionTry to optimize the expression.- Specified by:
optimizein classExpression- Parameters:
session- the session- Returns:
- the optimized expression
-
getUnenclosedSQL
public java.lang.StringBuilder getUnenclosedSQL(java.lang.StringBuilder builder, int sqlFlags)Description copied from class:ExpressionGet the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.- Overrides:
getUnenclosedSQLin classFunction1_2- Parameters:
builder- string buildersqlFlags- formatting flags- Returns:
- the specified string builder
-
getName
public java.lang.String getName()
Description copied from interface:NamedExpressionGet the name.- Returns:
- the name in uppercase
-
-