Search in sources :

Example 1 with LocalTime

use of java.time.LocalTime in project morphia by mongodb.

the class Java8EntityTest method rangeQueries.

@Test
public void rangeQueries() {
    Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
    LocalDate localDate = LocalDate.of(1995, 10, 15);
    LocalDateTime localDateTime = LocalDateTime.of(2016, 4, 10, 14, 15, 16, 123 * 1000000);
    LocalTime localTime = LocalTime.of(10, 29, 15, 848493);
    for (int i = 0; i < 10; i++) {
        createEntity(getDs(), instant.plus(i, DAYS), localDate.plus(i, DAYS), localDateTime.plus(i, DAYS), localTime.plus(i, ChronoUnit.HOURS));
    }
    Assert.assertEquals(2L, getDs().find(Java8Entity.class).field("instant").lessThanOrEq(instant.plus(1, DAYS)).count());
    Assert.assertEquals(1L, getDs().find(Java8Entity.class).field("localDate").equal(localDate.plus(1, DAYS)).count());
    Assert.assertEquals(0L, getDs().find(Java8Entity.class).field("localDate").equal(localDate.minus(1, DAYS)).count());
    Assert.assertEquals(9L, getDs().find(Java8Entity.class).field("localDateTime").notEqual(localDateTime.plus(6, DAYS)).count());
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 2 with LocalTime

use of java.time.LocalTime in project morphia by mongodb.

the class Java8EntityTest method queries.

@Test
public void queries() {
    Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
    LocalDate localDate = LocalDate.of(1995, 10, 15);
    LocalDateTime localDateTime = LocalDateTime.of(2016, 4, 10, 14, 15, 16, 123 * 1000000);
    LocalTime localTime = LocalTime.of(10, 29, 15, 848000000);
    Java8Entity entity = createEntity(getDs(), instant, localDate, localDateTime, localTime);
    compare(getDs(), entity, "instant", instant);
    compare(getDs(), entity, "localDate", localDate);
    compare(getDs(), entity, "localDateTime", localDateTime);
    compare(getDs(), entity, "localTime", localTime);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 3 with LocalTime

use of java.time.LocalTime in project morphia by mongodb.

the class LocalTimeConverterTest method testConversion.

@Test
public void testConversion() throws ParseException {
    final LocalTime time = LocalTime.of(12, 30, 45);
    compare(LocalTime.class, LocalTime.now());
    assertFormat(time, 45045000L);
}
Also used : LocalTime(java.time.LocalTime) Test(org.junit.Test)

Example 4 with LocalTime

use of java.time.LocalTime in project JFoenix by jfoenixadmin.

the class JFXTimePickerContent method createContentPane.

protected BorderPane createContentPane(LocalTime time) {
    Circle circle = new Circle(contentCircleRadius);
    circle.setFill(Color.rgb(224, 224, 224, 0.67));
    EventHandler<? super MouseEvent> mouseActionHandler = (event) -> {
        double dx = event.getX();
        double dy = event.getY();
        double theta = Math.atan2(dy, dx);
        int index = (int) Math.round((180 + Math.toDegrees(theta)) / angle.get());
        pointerRotate.get().setAngle(index * angle.get());
        int timeValue = (index + 9) % 12 == 0 ? 12 : (index + 9) % 12;
        if (unit.get() == TimeUnit.MINUTES)
            timeValue = (index + 45) % 60 == 0 ? 0 : (index + 45) % 60;
        timeLabel.get().setText(unit.get() == TimeUnit.MINUTES ? unitConverter.toString(timeValue) : timeValue + "");
        updateValue();
    };
    circle.setOnMousePressed(mouseActionHandler);
    circle.setOnMouseDragged(mouseActionHandler);
    hoursContent = createHoursContent(time);
    hoursContent.setMouseTransparent(true);
    minutesContent = createMinutesContent(time);
    minutesContent.setOpacity(0);
    minutesContent.setMouseTransparent(true);
    StackPane contentPane = new StackPane();
    contentPane.getChildren().addAll(circle, hoursContent, minutesContent);
    contentPane.setPadding(new Insets(12));
    BorderPane contentContainer = new BorderPane();
    contentContainer.setCenter(contentPane);
    contentContainer.setMinHeight(50);
    contentContainer.setPadding(new Insets(2, 12, 2, 12));
    return contentContainer;
}
Also used : EventHandler(javafx.event.EventHandler) FontWeight(javafx.scene.text.FontWeight) Pos(javafx.geometry.Pos) Color(javafx.scene.paint.Color) javafx.beans.property(javafx.beans.property) Label(javafx.scene.control.Label) javafx.scene.layout(javafx.scene.layout) FormatStyle(java.time.format.FormatStyle) Rotate(javafx.scene.transform.Rotate) MouseEvent(javafx.scene.input.MouseEvent) javafx.animation(javafx.animation) Font(javafx.scene.text.Font) Rectangle(javafx.scene.shape.Rectangle) Group(javafx.scene.Group) JFXTimePicker(com.jfoenix.controls.JFXTimePicker) Line(javafx.scene.shape.Line) NumberStringConverter(javafx.util.converter.NumberStringConverter) Duration(javafx.util.Duration) Insets(javafx.geometry.Insets) Paint(javafx.scene.paint.Paint) Locale(java.util.Locale) LocalTime(java.time.LocalTime) LocalTimeStringConverter(javafx.util.converter.LocalTimeStringConverter) Circle(javafx.scene.shape.Circle) Circle(javafx.scene.shape.Circle) Insets(javafx.geometry.Insets)

Example 5 with LocalTime

use of java.time.LocalTime in project jOOQ by jOOQ.

the class DefaultBinding method get.

@SuppressWarnings("unchecked")
@Override
public void get(BindingGetResultSetContext<U> ctx) throws SQLException {
    T result = null;
    if (type == Blob.class) {
        result = (T) ctx.resultSet().getBlob(ctx.index());
    } else if (type == Boolean.class) {
        result = (T) wasNull(ctx.resultSet(), Boolean.valueOf(ctx.resultSet().getBoolean(ctx.index())));
    } else if (type == BigInteger.class) {
        // The SQLite JDBC driver doesn't support BigDecimals
        if (ctx.configuration().dialect() == SQLDialect.SQLITE) {
            result = Convert.convert(ctx.resultSet().getString(ctx.index()), (Class<T>) BigInteger.class);
        } else {
            BigDecimal b = ctx.resultSet().getBigDecimal(ctx.index());
            result = (T) (b == null ? null : b.toBigInteger());
        }
    } else if (type == BigDecimal.class) {
        // The SQLite JDBC driver doesn't support BigDecimals
        if (ctx.configuration().dialect() == SQLDialect.SQLITE) {
            result = Convert.convert(ctx.resultSet().getString(ctx.index()), (Class<T>) BigDecimal.class);
        } else {
            result = (T) ctx.resultSet().getBigDecimal(ctx.index());
        }
    } else if (type == Byte.class) {
        result = (T) wasNull(ctx.resultSet(), Byte.valueOf(ctx.resultSet().getByte(ctx.index())));
    } else if (type == byte[].class) {
        result = (T) ctx.resultSet().getBytes(ctx.index());
    } else if (type == Clob.class) {
        result = (T) ctx.resultSet().getClob(ctx.index());
    } else if (type == Date.class) {
        result = (T) getDate(ctx.family(), ctx.resultSet(), ctx.index());
    } else if (type == Double.class) {
        result = (T) wasNull(ctx.resultSet(), Double.valueOf(ctx.resultSet().getDouble(ctx.index())));
    } else if (type == Float.class) {
        result = (T) wasNull(ctx.resultSet(), Float.valueOf(ctx.resultSet().getFloat(ctx.index())));
    } else if (type == Integer.class) {
        result = (T) wasNull(ctx.resultSet(), Integer.valueOf(ctx.resultSet().getInt(ctx.index())));
    } else if (type == LocalDate.class) {
        result = (T) localDate(getDate(ctx.family(), ctx.resultSet(), ctx.index()));
    } else if (type == LocalTime.class) {
        result = (T) localTime(getTime(ctx.family(), ctx.resultSet(), ctx.index()));
    } else if (type == LocalDateTime.class) {
        result = (T) localDateTime(getTimestamp(ctx.family(), ctx.resultSet(), ctx.index()));
    } else if (type == Long.class) {
        result = (T) wasNull(ctx.resultSet(), Long.valueOf(ctx.resultSet().getLong(ctx.index())));
    } else if (type == OffsetTime.class) {
        result = (T) offsetTime(ctx.resultSet().getString(ctx.index()));
    } else if (type == OffsetDateTime.class) {
        result = (T) offsetDateTime(ctx.resultSet().getString(ctx.index()));
    } else if (type == Short.class) {
        result = (T) wasNull(ctx.resultSet(), Short.valueOf(ctx.resultSet().getShort(ctx.index())));
    } else if (type == String.class) {
        result = (T) ctx.resultSet().getString(ctx.index());
    } else if (type == Time.class) {
        result = (T) getTime(ctx.family(), ctx.resultSet(), ctx.index());
    } else if (type == Timestamp.class) {
        result = (T) getTimestamp(ctx.family(), ctx.resultSet(), ctx.index());
    } else if (type == YearToMonth.class) {
        if (ctx.family() == POSTGRES) {
            Object object = ctx.resultSet().getObject(ctx.index());
            result = (T) (object == null ? null : PostgresUtils.toYearToMonth(object));
        } else {
            String string = ctx.resultSet().getString(ctx.index());
            result = (T) (string == null ? null : YearToMonth.valueOf(string));
        }
    } else if (type == DayToSecond.class) {
        if (ctx.family() == POSTGRES) {
            Object object = ctx.resultSet().getObject(ctx.index());
            result = (T) (object == null ? null : PostgresUtils.toDayToSecond(object));
        } else {
            String string = ctx.resultSet().getString(ctx.index());
            result = (T) (string == null ? null : DayToSecond.valueOf(string));
        }
    } else if (type == UByte.class) {
        result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UByte.class);
    } else if (type == UShort.class) {
        result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UShort.class);
    } else if (type == UInteger.class) {
        result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UInteger.class);
    } else if (type == ULong.class) {
        result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), ULong.class);
    } else if (type == UUID.class) {
        switch(ctx.family()) {
            // java.util.UUID data type
            case H2:
            case POSTGRES:
                {
                    result = (T) ctx.resultSet().getObject(ctx.index());
                    break;
                }
            // emulates the type
            default:
                {
                    result = (T) Convert.convert(ctx.resultSet().getString(ctx.index()), UUID.class);
                    break;
                }
        }
    } else // The type byte[] is handled earlier. byte[][] can be handled here
    if (type.isArray()) {
        switch(ctx.family()) {
            case POSTGRES:
                {
                    result = pgGetArray(ctx, ctx.resultSet(), type, ctx.index());
                    break;
                }
            default:
                // Note: due to a HSQLDB bug, it is not recommended to call rs.getObject() here:
                // See https://sourceforge.net/tracker/?func=detail&aid=3181365&group_id=23316&atid=378131
                result = (T) convertArray(ctx.resultSet().getArray(ctx.index()), (Class<? extends Object[]>) type);
                break;
        }
    } else if (EnumType.class.isAssignableFrom(type)) {
        result = (T) getEnumType((Class<EnumType>) type, ctx.resultSet().getString(ctx.index()));
    } else if (Record.class.isAssignableFrom(type)) {
        switch(ctx.family()) {
            case POSTGRES:
                result = (T) pgNewRecord(type, null, ctx.resultSet().getObject(ctx.index()));
                break;
            default:
                result = (T) ctx.resultSet().getObject(ctx.index(), typeMap(type, ctx.configuration()));
                break;
        }
    } else if (Result.class.isAssignableFrom(type)) {
        ResultSet nested = (ResultSet) ctx.resultSet().getObject(ctx.index());
        result = (T) DSL.using(ctx.configuration()).fetch(nested);
    } else {
        result = (T) unlob(ctx.resultSet().getObject(ctx.index()));
    }
    // [#4372] Attach records if possible / required
    if (result instanceof Attachable && attachRecords(ctx.configuration()))
        ((Attachable) result).attach(ctx.configuration());
    ctx.value(converter.from(result));
}
Also used : LocalDateTime(java.time.LocalDateTime) Time(java.sql.Time) LocalTime(java.time.LocalTime) OffsetTime(java.time.OffsetTime) OffsetDateTime(java.time.OffsetDateTime) LocalDateTime(java.time.LocalDateTime) PostgresUtils.toPGArrayString(org.jooq.util.postgres.PostgresUtils.toPGArrayString) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) LocalDate(java.time.LocalDate) Date(java.sql.Date) Result(org.jooq.Result) UByte(org.jooq.types.UByte) OffsetTime(java.time.OffsetTime) EnumType(org.jooq.EnumType) UInteger(org.jooq.types.UInteger) ResultSet(java.sql.ResultSet) MockResultSet(org.jooq.tools.jdbc.MockResultSet) UUID(java.util.UUID) Attachable(org.jooq.Attachable) UShort(org.jooq.types.UShort) YearToMonth(org.jooq.types.YearToMonth)

Aggregations

LocalTime (java.time.LocalTime)676 Test (org.junit.Test)262 Test (org.testng.annotations.Test)173 LocalDate (java.time.LocalDate)156 LocalDateTime (java.time.LocalDateTime)130 ZonedDateTime (java.time.ZonedDateTime)36 Date (java.util.Date)32 Instant (java.time.Instant)30 OffsetDateTime (java.time.OffsetDateTime)30 DateTimeFormatter (java.time.format.DateTimeFormatter)27 Test (org.junit.jupiter.api.Test)27 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)23 ZoneOffset (java.time.ZoneOffset)23 ZoneId (java.time.ZoneId)22 ArrayList (java.util.ArrayList)19 BigDecimal (java.math.BigDecimal)18 TemporalAccessor (java.time.temporal.TemporalAccessor)18 TemporalAmount (java.time.temporal.TemporalAmount)18 Time (java.sql.Time)17 Clock (java.time.Clock)17