Search in sources :

Example 11 with LocalTime

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

the class JodaTimeConverterFactoryProducer method produce.

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

        @Override
        public Converter<Date, DateTime> newConverter(ConvertingTypes targetedTypes, 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 AbstractConverterFactory<LocalDateTime, Date>(LocalDateTime.class, Date.class) {

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

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

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

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

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

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

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

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

        @Override
        public Converter<? super ReadablePartial, String> newConverter(ConvertingTypes targetedTypes, Object... params) {
            DateTimeFormatter dateTimeFormatter = JodaTimeHelper.getDateTimeFormatter(params);
            if (dateTimeFormatter != null) {
                return new JodaReadablePartialToStringConverter(dateTimeFormatter);
            } else {
                return ToStringConverter.INSTANCE;
            }
        }
    });
}
Also used : DateToJodaDateTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaDateTimeConverter) LocalDateTime(org.joda.time.LocalDateTime) DateToJodaLocalDateTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalDateTimeConverter) JodaInstantTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaInstantTojuDateConverter) ReadableInstant(org.joda.time.ReadableInstant) JodaReadablePartialToStringConverter(org.simpleflatmapper.converter.joda.impl.JodaReadablePartialToStringConverter) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) JodaReadableInstantToStringConverter(org.simpleflatmapper.converter.joda.impl.JodaReadableInstantToStringConverter) ConvertingTypes(org.simpleflatmapper.converter.ConvertingTypes) CharSequenceToJodaDateTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaDateTimeConverter) ReadablePartial(org.joda.time.ReadablePartial) JodaLocalTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalTimeTojuDateConverter) CharSequenceToJodaInstantConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaInstantConverter) CharSequenceToJodaDateTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaDateTimeConverter) JodaReadableInstantToStringConverter(org.simpleflatmapper.converter.joda.impl.JodaReadableInstantToStringConverter) DateToJodaDateTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaDateTimeConverter) JodaReadablePartialToStringConverter(org.simpleflatmapper.converter.joda.impl.JodaReadablePartialToStringConverter) CharSequenceToJodaLocalTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalTimeConverter) DateToJodaLocalDateConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalDateConverter) CharSequenceToJodaLocalDateTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalDateTimeConverter) DateToJodaInstantConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaInstantConverter) JodaLocalDateTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalDateTojuDateConverter) ToStringConverter(org.simpleflatmapper.converter.ToStringConverter) CharSequenceToJodaLocalDateConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalDateConverter) DateToJodaLocalTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalTimeConverter) JodaLocalTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalTimeTojuDateConverter) JodaLocalDateTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalDateTimeTojuDateConverter) Converter(org.simpleflatmapper.converter.Converter) JodaInstantTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaInstantTojuDateConverter) JodaDateTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaDateTimeTojuDateConverter) DateToJodaLocalDateTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalDateTimeConverter) JodaLocalDateTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalDateTojuDateConverter) JodaDateTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaDateTimeTojuDateConverter) CharSequenceToJodaInstantConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaInstantConverter) DateToJodaLocalDateConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalDateConverter) LocalTime(org.joda.time.LocalTime) CharSequenceToJodaLocalTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalTimeConverter) ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) CharSequenceToJodaLocalDateConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalDateConverter) JodaLocalDateTimeTojuDateConverter(org.simpleflatmapper.converter.joda.impl.JodaLocalDateTimeTojuDateConverter) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) DateToJodaInstantConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaInstantConverter) CharSequenceToJodaLocalDateTimeConverter(org.simpleflatmapper.converter.joda.impl.CharSequenceToJodaLocalDateTimeConverter) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateToJodaLocalTimeConverter(org.simpleflatmapper.converter.joda.impl.DateToJodaLocalTimeConverter)

Example 12 with LocalTime

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

the class JodaConversionTest method testSourceToTargetMappingForStrings.

@Test
public void testSourceToTargetMappingForStrings() {
    Source src = new Source();
    src.setLocalTime(new LocalTime(0, 0));
    src.setLocalDate(new LocalDate(2014, 1, 1));
    src.setLocalDateTime(new LocalDateTime(2014, 1, 1, 0, 0));
    src.setDateTime(new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.UTC));
    // with given format
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(src);
    assertThat(target).isNotNull();
    assertThat(target.getDateTime()).isEqualTo("01.01.2014 00:00 UTC");
    assertThat(target.getLocalDateTime()).isEqualTo("01.01.2014 00:00");
    assertThat(target.getLocalDate()).isEqualTo("01.01.2014");
    assertThat(target.getLocalTime()).isEqualTo("00:00");
    // and now with default mappings
    target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping(src);
    assertThat(target).isNotNull();
    assertThat(target.getDateTime()).isEqualTo("1. Januar 2014 00:00:00 UTC");
    assertThat(target.getLocalDateTime()).isEqualTo("1. Januar 2014 00:00:00");
    assertThat(target.getLocalDate()).isEqualTo("1. Januar 2014");
    assertThat(target.getLocalTime()).isEqualTo("00:00:00");
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) Test(org.junit.Test)

Example 13 with LocalTime

use of org.joda.time.LocalTime in project grafikon by jub77.

the class TimeConverter method convertIntToTextNNFull.

/**
 * converts from seconds to textual representation (not normalized).
 *
 * @param time time in seconds
 * @return textual representation
 */
public String convertIntToTextNNFull(int time) {
    LocalTime lt = this.getLocalTime(time);
    String result = lt.toString(printFull);
    if (time == TimeInterval.DAY) {
        result = result.replace("00:", "24:");
    }
    return result;
}
Also used : LocalTime(org.joda.time.LocalTime)

Example 14 with LocalTime

use of org.joda.time.LocalTime in project grafikon by jub77.

the class TimeConverter method convertIntToTextImpl.

private String convertIntToTextImpl(int time, boolean fixed, DateTimeFormatter shortFormat, DateTimeFormatter longFormat) {
    LocalTime localTime = this.getLocalTime(time);
    String timeStr = null;
    if (localTime.getSecondOfMinute() == 0 && !fixed) {
        timeStr = localTime.toString(shortFormat);
    } else {
        timeStr = localTime.toString(longFormat);
    }
    return timeStr;
}
Also used : LocalTime(org.joda.time.LocalTime)

Example 15 with LocalTime

use of org.joda.time.LocalTime in project osm-contributor by jawg.

the class OpeningMonthValueParserTest method nonStop2.

@Test
public void nonStop2() {
    OpeningMonth openingMonth = new OpeningMonth();
    OpeningHours openingHours = new OpeningHours();
    openingMonth.setMonthActivated(0, true);
    openingMonth.setMonthActivated(1, true);
    openingMonth.setMonthActivated(7, true);
    openingMonth.setMonthActivated(8, true);
    openingMonth.setMonthActivated(10, true);
    openingMonth.addOpeningHours(openingHours);
    openingHours.setDayActivated(0, true);
    openingHours.setDayActivated(1, true);
    openingHours.setDayActivated(2, true);
    openingHours.setDayActivated(3, true);
    openingHours.setDayActivated(4, true);
    openingHours.setDayActivated(5, true);
    openingHours.setDayActivated(6, true);
    openingHours.setFromTime(new LocalTime(23, 59));
    openingHours.setToTime(new LocalTime(23, 58));
    Assert.assertEquals(parser.toValue(openingMonth), "Jan-Feb,Aug-Sep,Nov: 24/7");
}
Also used : LocalTime(org.joda.time.LocalTime) OpeningMonth(io.jawg.osmcontributor.model.utils.OpeningMonth) OpeningHours(io.jawg.osmcontributor.model.utils.OpeningHours) Test(org.junit.Test)

Aggregations

LocalTime (org.joda.time.LocalTime)81 Test (org.junit.Test)39 OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)17 LocalDate (org.joda.time.LocalDate)14 DateTime (org.joda.time.DateTime)13 LocalDateTime (org.joda.time.LocalDateTime)13 Date (java.util.Date)11 DateTimeZone (org.joda.time.DateTimeZone)10 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)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 TimePickerDialog (android.app.TimePickerDialog)1