diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 1571401459..e72aaff02d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -13539,6 +13539,122 @@ public class DSL { return new DateAdd(nullSafe(date), nullSafe(interval).neg(), datePart); } + /** + * Add an interval to a timestamp. + *

+ * This translates into any dialect + * + * @see Field#add(Number) + */ + @Support + public static Field localDateTimeAdd(LocalDateTime timestamp, Number interval) { + return localDateTimeAdd(Tools.field(timestamp), Tools.field(interval)); + } + + /** + * Add an interval to a timestamp. + *

+ * This translates into any dialect + * + * @see Field#add(Field) + */ + @Support + public static Field localDateTimeAdd(Field timestamp, Field interval) { + return nullSafe(timestamp).add(interval); + } + + /** + * Add an interval to a timestamp, given a date part. + *

+ * This translates into any dialect + */ + @Support + public static Field localDateTimeAdd(LocalDateTime date, Number interval, DatePart datePart) { + return new DateAdd(Tools.field(date), Tools.field(interval), datePart); + } + + /** + * Add an interval to a timestamp, given a date part. + *

+ * This translates into any dialect + */ + @Support + public static Field localDateTimeAdd(LocalDateTime date, Field interval, DatePart datePart) { + return new DateAdd(Tools.field(date), nullSafe(interval), datePart); + } + + /** + * Add an interval to a timestamp, given a date part. + *

+ * This translates into any dialect + */ + @Support + public static Field localDateTimeAdd(Field date, Number interval, DatePart datePart) { + return new DateAdd(nullSafe(date), Tools.field(interval), datePart); + } + + /** + * Add an interval to a timestamp, given a date part. + *

+ * This translates into any dialect + */ + @Support + public static Field localDateTimeAdd(Field date, Field interval, DatePart datePart) { + return new DateAdd(nullSafe(date), nullSafe(interval), datePart); + } + + /** + * Get the timestamp difference as a INTERVAL DAY TO SECOND + * type. + *

+ * This translates into any dialect + * + * @see Field#sub(Field) + */ + @Support + public static Field localDateTimeDiff(LocalDateTime timestamp1, LocalDateTime timestamp2) { + return localDateTimeDiff(Tools.field(timestamp1), Tools.field(timestamp2)); + } + + /** + * Get the timestamp difference as a INTERVAL DAY TO SECOND + * type. + *

+ * This translates into any dialect + * + * @see Field#sub(Field) + */ + @Support + public static Field localDateTimeDiff(Field timestamp1, LocalDateTime timestamp2) { + return localDateTimeDiff(nullSafe(timestamp1), Tools.field(timestamp2)); + } + + /** + * Get the timestamp difference as a INTERVAL DAY TO SECOND + * type. + *

+ * This translates into any dialect + * + * @see Field#sub(Field) + */ + @Support + public static Field localDateTimeDiff(LocalDateTime timestamp1, Field timestamp2) { + return localDateTimeDiff(Tools.field(timestamp1), nullSafe(timestamp2)); + } + + /** + * Get the timestamp difference as a INTERVAL DAY TO SECOND + * type. + *

+ * This translates into any dialect + * + * @see Field#sub(Field) + */ + @Support + public static Field localDateTimeDiff(Field timestamp1, Field timestamp2) { + return new TimestampDiff(nullSafe(timestamp1), nullSafe(timestamp2)); + } + /** diff --git a/jOOQ/src/main/java/org/jooq/impl/TimestampDiff.java b/jOOQ/src/main/java/org/jooq/impl/TimestampDiff.java index 49bbc70776..c45ced13ab 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TimestampDiff.java +++ b/jOOQ/src/main/java/org/jooq/impl/TimestampDiff.java @@ -40,8 +40,6 @@ package org.jooq.impl; import static org.jooq.impl.DSL.function; import static org.jooq.impl.SQLDataType.INTEGER; -import java.sql.Timestamp; - import org.jooq.Configuration; import org.jooq.Field; import org.jooq.types.DayToSecond; @@ -56,10 +54,10 @@ final class TimestampDiff extends AbstractFunction { */ private static final long serialVersionUID = -4813228000332771961L; - private final Field timestamp1; - private final Field timestamp2; + private final Field timestamp1; + private final Field timestamp2; - TimestampDiff(Field timestamp1, Field timestamp2) { + TimestampDiff(Field timestamp1, Field timestamp2) { super("timestampdiff", SQLDataType.INTERVALDAYTOSECOND, timestamp1, timestamp2); this.timestamp1 = timestamp1;