[#3288] Add DSL.date(String), DSL.time(String), and DSL.timestamp(String), as shortcuts for respective valueOf() methods
This commit is contained in:
parent
814cd7d549
commit
03e57ff13d
@ -977,17 +977,26 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
return;
|
||||
}
|
||||
|
||||
Field<Date> d = date(inline(Timestamp.valueOf("1970-01-01 02:00:00.0")));
|
||||
Field<Time> t = time(inline(Timestamp.valueOf("1970-01-01 02:00:00.0")));
|
||||
Field<Timestamp> ts = timestamp(inline(Date.valueOf("1970-01-01")));
|
||||
Field<Date> d1 = date(inline(Timestamp.valueOf("1970-01-01 02:00:00.0")));
|
||||
Field<Time> t1 = time(inline(Timestamp.valueOf("1970-01-01 02:00:00.0")));
|
||||
Field<Timestamp> ts1 = timestamp(inline(Date.valueOf("1970-01-01")));
|
||||
|
||||
Record3<Date, Time, Timestamp> record =
|
||||
create().select(d, t, ts)
|
||||
Field<Date> d2 = date("1970-01-01");
|
||||
Field<Time> t2 = time("02:00:00");
|
||||
Field<Timestamp> ts2 = timestamp("1970-01-01 02:00:00.0");
|
||||
|
||||
Record record =
|
||||
create().select(d1, t1, ts1)
|
||||
.select(d2, t2, ts2)
|
||||
.fetchOne();
|
||||
|
||||
assertEquals("1970-01-01 00:00:00.0", record.getValue(ts).toString());
|
||||
assertEquals("1970-01-01", record.getValue(d).toString());
|
||||
assertEquals("02:00:00", record.getValue(t).toString());
|
||||
assertEquals("1970-01-01 00:00:00.0", record.getValue(ts1).toString());
|
||||
assertEquals("1970-01-01", record.getValue(d1).toString());
|
||||
assertEquals("02:00:00", record.getValue(t1).toString());
|
||||
|
||||
assertEquals("1970-01-01 02:00:00.0", record.getValue(ts2).toString());
|
||||
assertEquals("1970-01-01", record.getValue(d2).toString());
|
||||
assertEquals("02:00:00", record.getValue(t2).toString());
|
||||
}
|
||||
|
||||
public void testFunctionsOnDates() throws Exception {
|
||||
|
||||
@ -228,6 +228,7 @@ import org.jooq.api.annotation.Transition;
|
||||
import org.jooq.conf.RenderNameStyle;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
import org.jooq.tools.Convert;
|
||||
import org.jooq.tools.jdbc.JDBCUtils;
|
||||
import org.jooq.types.DayToSecond;
|
||||
|
||||
@ -8482,6 +8483,14 @@ public class DSL {
|
||||
return extract(field, DatePart.SECOND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string value to a <code>DATE</code>.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Date> date(String value) {
|
||||
return Utils.field(Convert.convert(value, Date.class), Date.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a temporal value to a <code>DATE</code>.
|
||||
*/
|
||||
@ -8498,6 +8507,14 @@ public class DSL {
|
||||
return new DateOrTime<Date>(field, SQLDataType.DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string value to a <code>TIME</code>.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Time> time(String value) {
|
||||
return Utils.field(Convert.convert(value, Time.class), Time.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a temporal value to a <code>TIME</code>.
|
||||
*/
|
||||
@ -8514,6 +8531,14 @@ public class DSL {
|
||||
return new DateOrTime<Time>(field, SQLDataType.TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string value to a <code>TIMESTAMP</code>.
|
||||
*/
|
||||
@Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
public static Field<Timestamp> timestamp(String value) {
|
||||
return Utils.field(Convert.convert(value, Timestamp.class), Timestamp.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a temporal value to a <code>TIMESTAMP</code>.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user