[#3781] Add support for DSL.trunc(date, DatePart) for H2
This commit is contained in:
parent
2ca7bff19c
commit
bcc93dfabb
@ -8009,7 +8009,7 @@ public class DSL {
|
||||
/**
|
||||
* Truncate a date to the beginning of the day.
|
||||
*/
|
||||
@Support({ CUBRID, HSQLDB, POSTGRES })
|
||||
@Support({ CUBRID, H2, HSQLDB, POSTGRES })
|
||||
public static Field<Date> trunc(Date date) {
|
||||
return trunc(date, DatePart.DAY);
|
||||
}
|
||||
@ -8017,7 +8017,7 @@ public class DSL {
|
||||
/**
|
||||
* Truncate a date to a given datepart.
|
||||
*/
|
||||
@Support({ CUBRID, HSQLDB, POSTGRES })
|
||||
@Support({ CUBRID, H2, HSQLDB, POSTGRES })
|
||||
public static Field<Date> trunc(Date date, DatePart part) {
|
||||
return trunc(Utils.field(date), part);
|
||||
}
|
||||
@ -8025,7 +8025,7 @@ public class DSL {
|
||||
/**
|
||||
* Truncate a timestamp to the beginning of the day.
|
||||
*/
|
||||
@Support({ CUBRID, HSQLDB, POSTGRES })
|
||||
@Support({ CUBRID, H2, HSQLDB, POSTGRES })
|
||||
public static Field<Timestamp> trunc(Timestamp timestamp) {
|
||||
return trunc(timestamp, DatePart.DAY);
|
||||
}
|
||||
@ -8033,7 +8033,7 @@ public class DSL {
|
||||
/**
|
||||
* Truncate a timestamp to a given datepart.
|
||||
*/
|
||||
@Support({ CUBRID, HSQLDB, POSTGRES })
|
||||
@Support({ CUBRID, H2, HSQLDB, POSTGRES })
|
||||
public static Field<Timestamp> trunc(Timestamp timestamp, DatePart part) {
|
||||
return trunc(Utils.field(timestamp), part);
|
||||
}
|
||||
@ -8041,7 +8041,7 @@ public class DSL {
|
||||
/**
|
||||
* Truncate a date or a timestamp to the beginning of the day.
|
||||
*/
|
||||
@Support({ CUBRID, HSQLDB, POSTGRES })
|
||||
@Support({ CUBRID, H2, HSQLDB, POSTGRES })
|
||||
public static <T extends java.util.Date> Field<T> trunc(Field<T> date) {
|
||||
return trunc(date, DatePart.DAY);
|
||||
}
|
||||
@ -8049,7 +8049,7 @@ public class DSL {
|
||||
/**
|
||||
* Truncate a date or a timestamp to a given datepart.
|
||||
*/
|
||||
@Support({ CUBRID, HSQLDB, POSTGRES })
|
||||
@Support({ CUBRID, H2, HSQLDB, POSTGRES })
|
||||
public static <T extends java.util.Date> Field<T> trunc(Field<T> date, DatePart part) {
|
||||
return new TruncDate<T>(date, part);
|
||||
}
|
||||
|
||||
@ -73,6 +73,7 @@ class TruncDate<T extends java.util.Date> extends AbstractFunction<T> {
|
||||
@Override
|
||||
final QueryPart getFunction0(Configuration configuration) {
|
||||
String keyword = null;
|
||||
String format = null;
|
||||
|
||||
switch (configuration.dialect().family()) {
|
||||
|
||||
@ -92,6 +93,20 @@ class TruncDate<T extends java.util.Date> extends AbstractFunction<T> {
|
||||
return field("{trunc}({0}, {1})", getDataType(), date, inline(keyword));
|
||||
}
|
||||
|
||||
case H2: {
|
||||
switch (part) {
|
||||
case YEAR: format = "yyyy"; break;
|
||||
case MONTH: format = "yyyy-MM"; break;
|
||||
case DAY: format = "yyyy-MM-dd"; break;
|
||||
case HOUR: format = "yyyy-MM-dd HH"; break;
|
||||
case MINUTE: format = "yyyy-MM-dd HH:mm"; break;
|
||||
case SECOND: format = "yyyy-MM-dd HH:mm:ss"; break;
|
||||
default: throwUnsupported();
|
||||
}
|
||||
|
||||
return field("{parsedatetime}({formatdatetime}({0}, {1}), {1})", getDataType(), date, inline(format));
|
||||
}
|
||||
|
||||
// These don't work yet and need better integration-testing:
|
||||
// ---------------------------------------------------------
|
||||
// case MARIADB:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user