[#5645] Add DSL.localDateAdd() localDateSub(), localDateDiff()
This commit is contained in:
parent
4360d7c29d
commit
cb306cbb6c
@ -11979,6 +11979,30 @@ public class DSL {
|
||||
return dateDiff(nullSafe(date1), Tools.field(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> dateDiff(Date date1, Field<Date> date2) {
|
||||
return dateDiff(Tools.field(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> dateDiff(Field<Date> date1, Field<Date> date2) {
|
||||
return new DateDiff<Date>(nullSafe(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date.
|
||||
* <p>
|
||||
@ -12107,30 +12131,6 @@ public class DSL {
|
||||
return new DateAdd<Date>(nullSafe(date), nullSafe(interval).neg(), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> dateDiff(Date date1, Field<Date> date2) {
|
||||
return dateDiff(Tools.field(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> dateDiff(Field<Date> date1, Field<Date> date2) {
|
||||
return new DateDiff(nullSafe(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a timestamp.
|
||||
* <p>
|
||||
@ -12247,6 +12247,186 @@ public class DSL {
|
||||
return new TimestampDiff(nullSafe(timestamp1), nullSafe(timestamp2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> localDateDiff(LocalDate date1, LocalDate date2) {
|
||||
return localDateDiff(Tools.field(date1), Tools.field(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> localDateDiff(Field<LocalDate> date1, LocalDate date2) {
|
||||
return localDateDiff(nullSafe(date1), Tools.field(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> localDateDiff(LocalDate date1, Field<LocalDate> date2) {
|
||||
return localDateDiff(Tools.field(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<Integer> localDateDiff(Field<LocalDate> date1, Field<LocalDate> date2) {
|
||||
return new DateDiff<LocalDate>(nullSafe(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#add(Number)
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateAdd(LocalDate date, Number interval) {
|
||||
return localDateAdd(Tools.field(date), Tools.field(interval));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#add(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateAdd(Field<LocalDate> date, Field<? extends Number> interval) {
|
||||
return nullSafe(date).add(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateAdd(LocalDate date, Number interval, DatePart datePart) {
|
||||
return localDateAdd(Tools.field(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateAdd(LocalDate date, Field<? extends Number> interval, DatePart datePart) {
|
||||
return localDateAdd(Tools.field(date), nullSafe(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateAdd(Field<LocalDate> date, Number interval, DatePart datePart) {
|
||||
return localDateAdd(nullSafe(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateAdd(Field<LocalDate> date, Field<? extends Number> interval, DatePart datePart) {
|
||||
return new DateAdd<LocalDate>(nullSafe(date), nullSafe(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a date.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#add(Number)
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateSub(LocalDate date, Number interval) {
|
||||
return localDateSub(Tools.field(date), Tools.field(interval));
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a date.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*
|
||||
* @see Field#add(Field)
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateSub(Field<LocalDate> date, Field<? extends Number> interval) {
|
||||
return nullSafe(date).sub(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateSub(LocalDate date, Number interval, DatePart datePart) {
|
||||
return localDateSub(Tools.field(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateSub(LocalDate date, Field<? extends Number> interval, DatePart datePart) {
|
||||
return localDateSub(Tools.field(date), nullSafe(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateSub(Field<LocalDate> date, Number interval, DatePart datePart) {
|
||||
return localDateSub(nullSafe(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a date, given a date part.
|
||||
* <p>
|
||||
* This translates into any dialect
|
||||
*/
|
||||
@Support
|
||||
public static Field<LocalDate> localDateSub(Field<LocalDate> date, Field<? extends Number> interval, DatePart datePart) {
|
||||
return new DateAdd<LocalDate>(nullSafe(date), nullSafe(interval).neg(), datePart);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Truncate a date to the beginning of the day.
|
||||
*/
|
||||
@ -12690,152 +12870,6 @@ public class DSL {
|
||||
return new DateOrTime<LocalDate>(field, SQLDataType.LOCALDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Integer> localDateDiff(LocalDate date1, LocalDate date2) {
|
||||
return localDateDiff(Tools.field(date1), Tools.field(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Integer> localDateDiff(Field<LocalDate> date1, LocalDate date2) {
|
||||
return localDateDiff(nullSafe(date1), Tools.field(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Integer> localDateDiff(LocalDate date1, Field<LocalDate> date2) {
|
||||
return localDateDiff(Tools.field(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date difference in number of days.
|
||||
*
|
||||
* @see Field#sub(Field)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Integer> localDateDiff(Field<LocalDate> date1, Field<LocalDate> date2) {
|
||||
return new LocalDateDiff(nullSafe(date1), nullSafe(date2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a {@link LocalDate}.
|
||||
*
|
||||
* @see Field#add(Number)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateAdd(LocalDate date, Number interval) {
|
||||
return localDateAdd(Tools.field(date), Tools.field(interval));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a {@link LocalDate}.
|
||||
*
|
||||
* @see Field#add(Field)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateAdd(Field<LocalDate> date, Field<? extends Number> interval) {
|
||||
return nullSafe(date).add(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateAdd(LocalDate date, Number interval, DatePart datePart) {
|
||||
return localDateAdd(Tools.field(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateAdd(LocalDate date, Field<? extends Number> interval, DatePart datePart) {
|
||||
return localDateAdd(Tools.field(date), nullSafe(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateAdd(Field<LocalDate> date, Number interval, DatePart datePart) {
|
||||
return localDateAdd(nullSafe(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an interval to a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateAdd(Field<LocalDate> date, Field<? extends Number> interval,
|
||||
DatePart datePart) {
|
||||
return new LocalDateAdd(nullSafe(date), nullSafe(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a {@link LocalDate}.
|
||||
*
|
||||
* @see Field#add(Number)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateSub(LocalDate date, Number interval) {
|
||||
return localDateSub(Tools.field(date), Tools.field(interval));
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a {@link LocalDate}.
|
||||
*
|
||||
* @see Field#add(Field)
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateSub(Field<LocalDate> date, Field<? extends Number> interval) {
|
||||
return nullSafe(date).sub(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateSub(LocalDate date, Number interval, DatePart datePart) {
|
||||
return localDateSub(Tools.field(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateSub(LocalDate date, Field<? extends Number> interval, DatePart datePart) {
|
||||
return localDateSub(Tools.field(date), nullSafe(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateSub(Field<LocalDate> date, Number interval, DatePart datePart) {
|
||||
return localDateSub(nullSafe(date), Tools.field(interval), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract an interval from a {@link LocalDate}, given a date part.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<LocalDate> localDateSub(Field<LocalDate> date, Field<? extends Number> interval,
|
||||
DatePart datePart) {
|
||||
return new LocalDateAdd(nullSafe(date), nullSafe(interval).neg(), datePart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string value to a <code>TIME</code>.
|
||||
*/
|
||||
|
||||
@ -48,7 +48,7 @@ import org.jooq.QueryPart;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class DateAdd<T extends java.util.Date> extends AbstractFunction<T> {
|
||||
final class DateAdd<T> extends AbstractFunction<T> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
|
||||
@ -36,25 +36,23 @@ package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.function;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Field;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class DateDiff extends AbstractFunction<Integer> {
|
||||
final class DateDiff<T> extends AbstractFunction<Integer> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -4813228000332771961L;
|
||||
|
||||
private final Field<Date> date1;
|
||||
private final Field<Date> date2;
|
||||
private final Field<T> date1;
|
||||
private final Field<T> date2;
|
||||
|
||||
DateDiff(Field<Date> date1, Field<Date> date2) {
|
||||
DateDiff(Field<T> date1, Field<T> date2) {
|
||||
super("datediff", SQLDataType.INTEGER, date1, date2);
|
||||
|
||||
this.date1 = date1;
|
||||
|
||||
@ -50,4 +50,4 @@ Authors and contributors of jOOQ or parts of jOOQ in alphabetical order:
|
||||
- Zoltan Tamasi
|
||||
|
||||
See the following website for details about contributing to jOOQ:
|
||||
https://github.com/jOOQ/jOOQ/blob/master/CONTRIBUTING.md
|
||||
https://github.com/jOOQ/jOOQ/blob/master/CONTRIBUTING.md
|
||||
Loading…
Reference in New Issue
Block a user