Search in sources :

Example 76 with LocalTime

use of org.joda.time.LocalTime in project tests by datanucleus.

the class JodaTimeTest method testLocalTime.

/**
 * Test for LocalTime persistence and retrieval.
 */
public void testLocalTime() {
    try {
        // Create some data we can use for access
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        LocalTime localTime1 = new LocalTime(15, 9, 26);
        LocalTime localTime2 = new LocalTime(7, 9, 26);
        try {
            tx.begin();
            JodaSample3 s = new JodaSample3(1, localTime1, localTime2);
            JodaSample3 s2 = new JodaSample3(2, null, null);
            em.persist(s);
            em.persist(s2);
            tx.commit();
        } catch (Exception e) {
            LOG.error("Error persisting LocalTime sample", e);
            fail("Error persisting LocalTime sample");
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
        // Retrieve the data
        em = emf.createEntityManager();
        tx = em.getTransaction();
        try {
            tx.begin();
            JodaSample3 s = em.find(JodaSample3.class, 1);
            LocalTime lt1 = s.getLocalTime1();
            assertNotNull("Retrieved LocalTime was null!", lt1);
            assertEquals("Hour was wrong", 15, lt1.getHourOfDay());
            assertEquals("Minute was wrong", 9, lt1.getMinuteOfHour());
            assertEquals("Second was wrong", 26, lt1.getSecondOfMinute());
            LocalTime lt2 = s.getLocalTime2();
            assertNotNull("Retrieved LocalTime was null!", lt2);
            assertEquals("Hour was wrong", 7, lt2.getHourOfDay());
            assertEquals("Minute was wrong", 9, lt2.getMinuteOfHour());
            assertEquals("Second was wrong", 26, lt2.getSecondOfMinute());
            JodaSample3 s2 = em.find(JodaSample3.class, 2);
            assertNull(s2.getLocalTime1());
            assertNull(s2.getLocalTime2());
            tx.commit();
        } catch (Exception e) {
            LOG.error("Error retrieving LocalTime data", e);
            fail("Error retrieving LocalTime data : " + e.getMessage());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
    } finally {
        clean(JodaSample3.class);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) LocalTime(org.joda.time.LocalTime) JodaSample3(org.datanucleus.samples.types.jodatime.JodaSample3)

Example 77 with LocalTime

use of org.joda.time.LocalTime in project qi4j-sdk by Qi4j.

the class DateTextFieldWithPicker method earliestDate.

public DateTextFieldWithPicker earliestDate(LocalDate newEarliestDate) {
    if (selectedDate != null && newEarliestDate.isAfter(selectedDate)) {
        throw new IllegalArgumentException("Earliest date can't be before selected day.");
    }
    earliestDate = newEarliestDate;
    // Input field validation - date should be _after_ minimumDate (not the same)
    LocalDate minimumDate = newEarliestDate.minusDays(1);
    Date convertedMinimumDate = new DateTime(minimumDate.toDateTime(new LocalTime())).toDate();
    add(DateValidator.minimum(convertedMinimumDate));
    return this;
}
Also used : LocalTime(org.joda.time.LocalTime) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 78 with LocalTime

use of org.joda.time.LocalTime in project drill by apache.

the class CompareFunctionsProcessor method visitSchemaPath.

@Override
public Boolean visitSchemaPath(SchemaPath path, LogicalExpression valueArg) throws RuntimeException {
    // If valueArg is null, this might be a IS NULL/IS NOT NULL type of query
    if (valueArg == null) {
        this.path = path;
        return true;
    }
    if (valueArg instanceof QuotedString) {
        this.value = SqlHelper.decodeStringAsValue(((QuotedString) valueArg).value);
        this.path = path;
        return true;
    }
    if (valueArg instanceof IntExpression) {
        this.value = KeyValueBuilder.initFrom(((IntExpression) valueArg).getInt());
        this.path = path;
        return true;
    }
    if (valueArg instanceof FloatExpression) {
        this.value = KeyValueBuilder.initFrom(((FloatExpression) valueArg).getFloat());
        this.path = path;
        return true;
    }
    if (valueArg instanceof BooleanExpression) {
        this.value = KeyValueBuilder.initFrom(((BooleanExpression) valueArg).getBoolean());
        this.path = path;
        return true;
    }
    if (valueArg instanceof Decimal28Expression) {
        this.value = KeyValueBuilder.initFrom(((Decimal28Expression) valueArg).getBigDecimal());
        this.path = path;
        return true;
    }
    if (valueArg instanceof Decimal38Expression) {
        this.value = KeyValueBuilder.initFrom(((Decimal38Expression) valueArg).getBigDecimal());
        this.path = path;
        return true;
    }
    if (valueArg instanceof DoubleExpression) {
        this.value = KeyValueBuilder.initFrom(((DoubleExpression) valueArg).getDouble());
        this.path = path;
        return true;
    }
    if (valueArg instanceof LongExpression) {
        this.value = KeyValueBuilder.initFrom(((LongExpression) valueArg).getLong());
        this.path = path;
        return true;
    }
    if (valueArg instanceof DateExpression) {
        long d = ((DateExpression) valueArg).getDate();
        final long MILLISECONDS_IN_A_DAY = (long) 1000 * 60 * 60 * 24;
        int daysSinceEpoch = (int) (d / MILLISECONDS_IN_A_DAY);
        this.value = KeyValueBuilder.initFrom(ODate.fromDaysSinceEpoch(daysSinceEpoch));
        this.path = path;
        return true;
    }
    if (valueArg instanceof TimeExpression) {
        int t = ((TimeExpression) valueArg).getTime();
        LocalTime lT = LocalTime.fromMillisOfDay(t);
        this.value = KeyValueBuilder.initFrom(new OTime(lT.getHourOfDay(), lT.getMinuteOfHour(), lT.getSecondOfMinute(), lT.getMillisOfSecond()));
        this.path = path;
        return true;
    }
    // See com.mapr.db.impl.ConditionImpl.is(FieldPath path, QueryCondition.Op op, BigDecimal value) method
    if (valueArg instanceof VarDecimalExpression) {
        this.value = KeyValueBuilder.initFrom(((VarDecimalExpression) valueArg).getBigDecimal().doubleValue());
        this.path = path;
        return true;
    }
    if (valueArg instanceof TimeStampExpression) {
        return visitTimestampExpr(path, (TimeStampExpression) valueArg);
    }
    return false;
}
Also used : VarDecimalExpression(org.apache.drill.common.expression.ValueExpressions.VarDecimalExpression) LocalTime(org.joda.time.LocalTime) IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) Decimal38Expression(org.apache.drill.common.expression.ValueExpressions.Decimal38Expression) DoubleExpression(org.apache.drill.common.expression.ValueExpressions.DoubleExpression) FloatExpression(org.apache.drill.common.expression.ValueExpressions.FloatExpression) TimeExpression(org.apache.drill.common.expression.ValueExpressions.TimeExpression) TimeStampExpression(org.apache.drill.common.expression.ValueExpressions.TimeStampExpression) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) BooleanExpression(org.apache.drill.common.expression.ValueExpressions.BooleanExpression) DateExpression(org.apache.drill.common.expression.ValueExpressions.DateExpression) Decimal28Expression(org.apache.drill.common.expression.ValueExpressions.Decimal28Expression) LongExpression(org.apache.drill.common.expression.ValueExpressions.LongExpression) OTime(org.ojai.types.OTime)

Example 79 with LocalTime

use of org.joda.time.LocalTime in project SimpleFlatMapper by arnaudroger.

the class JodaTimeConverterFactoryProducer method produce.

@Override
public void produce(Consumer<? super ContextualConverterFactory<?, ?>> consumer) {
    // Date to joda time
    factoryConverter(consumer, new AbstractContextualConverterFactory<Date, DateTime>(Date.class, DateTime.class) {

        @Override
        public ContextualConverter<Date, DateTime> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
            return new DateToJodaDateTimeConverter(JodaTimeHelper.getDateTimeZoneOrDefault(params));
        }
    });
    constantConverter(consumer, Date.class, Instant.class, new DateToJodaInstantConverter());
    constantConverter(consumer, Date.class, LocalDate.class, new DateToJodaLocalDateConverter());
    constantConverter(consumer, Date.class, LocalDateTime.class, new DateToJodaLocalDateTimeConverter());
    constantConverter(consumer, Date.class, LocalTime.class, new DateToJodaLocalTimeConverter());
    // joda time to date
    constantConverter(consumer, DateTime.class, Date.class, new JodaDateTimeTojuDateConverter());
    constantConverter(consumer, Instant.class, Date.class, new JodaInstantTojuDateConverter());
    constantConverter(consumer, LocalDate.class, Date.class, new JodaLocalDateTojuDateConverter());
    factoryConverter(consumer, new AbstractContextualConverterFactory<LocalDateTime, Date>(LocalDateTime.class, Date.class) {

        @Override
        public ContextualConverter<LocalDateTime, Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
            return new JodaLocalDateTimeTojuDateConverter(JodaTimeHelper.getDateTimeZoneOrDefault(params));
        }
    });
    factoryConverter(consumer, new AbstractContextualConverterFactory<LocalTime, Date>(LocalTime.class, Date.class) {

        @Override
        public ContextualConverter<LocalTime, Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
            return new JodaLocalTimeTojuDateConverter(JodaTimeHelper.getDateTimeZoneOrDefault(params));
        }
    });
    // char sequence to joda time
    factoryConverter(consumer, new AbstractMultiFormatContextualConverterFactory<CharSequence, DateTime>(CharSequence.class, DateTime.class) {

        @Override
        protected ContextualConverter<CharSequence, DateTime> newConverter(DateTimeFormatter formatter) {
            return new CharSequenceToJodaDateTimeConverter(formatter);
        }
    });
    factoryConverter(consumer, new AbstractMultiFormatContextualConverterFactory<CharSequence, Instant>(CharSequence.class, Instant.class) {

        @Override
        protected ContextualConverter<CharSequence, Instant> newConverter(DateTimeFormatter formatter) {
            return new CharSequenceToJodaInstantConverter(formatter);
        }
    });
    factoryConverter(consumer, new AbstractMultiFormatContextualConverterFactory<CharSequence, LocalDate>(CharSequence.class, LocalDate.class) {

        @Override
        protected ContextualConverter<CharSequence, LocalDate> newConverter(DateTimeFormatter formatter) {
            return new CharSequenceToJodaLocalDateConverter(formatter);
        }
    });
    factoryConverter(consumer, new AbstractMultiFormatContextualConverterFactory<CharSequence, LocalDateTime>(CharSequence.class, LocalDateTime.class) {

        @Override
        protected ContextualConverter<CharSequence, LocalDateTime> newConverter(DateTimeFormatter formatter) {
            return new CharSequenceToJodaLocalDateTimeConverter(formatter);
        }
    });
    factoryConverter(consumer, new AbstractMultiFormatContextualConverterFactory<CharSequence, LocalTime>(CharSequence.class, LocalTime.class) {

        @Override
        protected ContextualConverter<CharSequence, LocalTime> newConverter(DateTimeFormatter formatter) {
            return new CharSequenceToJodaLocalTimeConverter(formatter);
        }
    });
    factoryConverter(consumer, new AbstractContextualConverterFactory<ReadableInstant, String>(ReadableInstant.class, String.class) {

        @Override
        public ContextualConverter<? super ReadableInstant, String> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
            DateTimeFormatter dateTimeFormatter = JodaTimeHelper.getDateTimeFormatter(params);
            if (dateTimeFormatter != null) {
                return new JodaReadableInstantToStringConverter(dateTimeFormatter);
            } else {
                return ToStringConverter.INSTANCE;
            }
        }
    });
    factoryConverter(consumer, new AbstractContextualConverterFactory<ReadablePartial, String>(ReadablePartial.class, String.class) {

        @Override
        public ContextualConverter<? super ReadablePartial, String> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
            DateTimeFormatter dateTimeFormatter = JodaTimeHelper.getDateTimeFormatter(params);
            if (dateTimeFormatter != null) {
                return new JodaReadablePartialToStringConverter(dateTimeFormatter);
            } else {
                return ToStringConverter.INSTANCE;
            }
        }
    });
    // IFJAVA8_START
    constantConverter(consumer, LocalDateTime.class, java.time.LocalDateTime.class, new org.simpleflatmapper.converter.joda.impl.time.JodaLocalDateTimeTojuLocalDateTimeConverter());
    constantConverter(consumer, LocalDate.class, java.time.LocalDate.class, new org.simpleflatmapper.converter.joda.impl.time.JodaLocalDateTojuLocalDateConverter());
    constantConverter(consumer, LocalTime.class, java.time.LocalTime.class, new org.simpleflatmapper.converter.joda.impl.time.JodaLocalTimeTojuLocalTimeConverter());
    // IFJAVA8_END
    constantConverter(consumer, LocalTime.class, Long.class, new ContextualConverter<LocalTime, Long>() {

        @Override
        public Long convert(LocalTime in, Context context) throws Exception {
            if (in == null)
                return null;
            return TimeUnit.MILLISECONDS.toNanos(in.getMillisOfDay());
        }
    });
}
Also used : DateToJodaDateTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaDateTimeConverter) DateToJodaLocalDateTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalDateTimeConverter) JodaInstantTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaInstantTojuDateConverter) ReadableInstant(org.joda.time.ReadableInstant) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ContextFactoryBuilder(org.simpleflatmapper.converter.ContextFactoryBuilder) ReadablePartial(org.joda.time.ReadablePartial) JodaLocalTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalTimeTojuDateConverter) DateToJodaLocalDateConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalDateConverter) LocalTime(org.joda.time.LocalTime) ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) CharSequenceToJodaLocalDateConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalDateConverter) JodaLocalDateTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalDateTimeTojuDateConverter) DateToJodaInstantConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaInstantConverter) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) LocalDateTime(org.joda.time.LocalDateTime) JodaReadablePartialToStringConverter(org.simpleflatmapper.converter.joda.impl.JodaReadablePartialToStringConverter) JodaReadableInstantToStringConverter(org.simpleflatmapper.converter.joda.impl.JodaReadableInstantToStringConverter) ConvertingTypes(org.simpleflatmapper.converter.ConvertingTypes) CharSequenceToJodaDateTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaDateTimeConverter) JodaLocalDateTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalDateTojuDateConverter) JodaDateTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaDateTimeTojuDateConverter) CharSequenceToJodaInstantConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaInstantConverter) Context(org.simpleflatmapper.converter.Context) CharSequenceToJodaLocalTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalTimeConverter) ContextualConverter(org.simpleflatmapper.converter.ContextualConverter) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) CharSequenceToJodaLocalDateTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalDateTimeConverter) DateToJodaLocalTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalTimeConverter)

Example 80 with LocalTime

use of org.joda.time.LocalTime in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapIncompleteLocalTimeToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(LocalTimeToXmlGregorianCalendar.class)
public void shouldMapIncompleteLocalTimeToXmlGregorianCalendar() {
    LocalTimeBean in = new LocalTimeBean();
    LocalTime dt = new LocalTime(1, 1, 0, 100);
    in.setLocalTime(dt);
    XmlGregorianCalendarBean res = LocalTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(in);
    assertThat(res.getxMLGregorianCalendar().getYear()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMonth()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getDay()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getHour()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getSecond()).isEqualTo(0);
    assertThat(res.getxMLGregorianCalendar().getMillisecond()).isEqualTo(100);
    assertThat(res.getxMLGregorianCalendar().getTimezone()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
}
Also used : LocalTime(org.joda.time.LocalTime) XmlGregorianCalendarToLocalTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalTime) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

LocalTime (org.joda.time.LocalTime)83 Test (org.junit.Test)34 OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)17 LocalDate (org.joda.time.LocalDate)16 DateTime (org.joda.time.DateTime)15 LocalDateTime (org.joda.time.LocalDateTime)15 Date (java.util.Date)12 DateTimeZone (org.joda.time.DateTimeZone)10 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)6 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)5 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 ContentValues (android.content.ContentValues)2 Time (java.sql.Time)2 EntityManager (javax.persistence.EntityManager)2 EntityTransaction (javax.persistence.EntityTransaction)2 JodaSample3 (org.datanucleus.samples.types.jodatime.JodaSample3)2 DatePickerDialog (android.app.DatePickerDialog)1