Search in sources :

Example 6 with DefaultDateFormatSupplier

use of org.simpleflatmapper.util.date.DefaultDateFormatSupplier in project SimpleFlatMapper by arnaudroger.

the class JodaTimeHelper method getDateTimeFormatter.

public static DateTimeFormatter getDateTimeFormatter(Object... properties) {
    final DateTimeZone dateTimeZone = getDateTimeZone(properties);
    DefaultDateFormatSupplier defaultDateFormatSupplier = null;
    for (Object prop : properties) {
        DateTimeFormatter dateTimeFormatter = toDateTimeFormater(prop, dateTimeZone);
        if (dateTimeFormatter != null) {
            return dateTimeFormatter;
        } else if (prop instanceof DefaultDateFormatSupplier) {
            defaultDateFormatSupplier = (DefaultDateFormatSupplier) prop;
        }
    }
    if (defaultDateFormatSupplier != null) {
        return withZone(defaultDateFormatSupplier.get(), dateTimeZone);
    }
    return null;
}
Also used : DefaultDateFormatSupplier(org.simpleflatmapper.util.date.DefaultDateFormatSupplier) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone)

Example 7 with DefaultDateFormatSupplier

use of org.simpleflatmapper.util.date.DefaultDateFormatSupplier in project SimpleFlatMapper by arnaudroger.

the class JodaTimeHelperTest method testGetFormattersAndDefaultFormat.

@Test
public void testGetFormattersAndDefaultFormat() {
    LocalDateTime localDateTime = LocalDateTime.now();
    assertEquals(DateTimeFormat.forPattern("yyyy").print(localDateTime), JodaTimeHelper.getDateTimeFormatters(new DefaultDateFormatSupplier() {

        @Override
        public String get() {
            return "yyyy";
        }
    })[0].print(localDateTime));
    DateTimeFormatter[] dateTimeFormatters = JodaTimeHelper.getDateTimeFormatters(new DefaultDateFormatSupplier() {

        @Override
        public String get() {
            return "yyyy";
        }
    }, DateTimeFormat.fullDate());
    assertEquals(1, dateTimeFormatters.length);
    assertEquals(DateTimeFormat.fullDate().print(localDateTime), dateTimeFormatters[0].print(localDateTime));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) DefaultDateFormatSupplier(org.simpleflatmapper.util.date.DefaultDateFormatSupplier) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 8 with DefaultDateFormatSupplier

use of org.simpleflatmapper.util.date.DefaultDateFormatSupplier in project SimpleFlatMapper by arnaudroger.

the class JodaTimeHelperTest method testGetFormatterAndDefaultFormat.

@Test
public void testGetFormatterAndDefaultFormat() {
    LocalDateTime localDateTime = LocalDateTime.now();
    assertEquals(DateTimeFormat.forPattern("yyyy").print(localDateTime), JodaTimeHelper.getDateTimeFormatter(new DefaultDateFormatSupplier() {

        @Override
        public String get() {
            return "yyyy";
        }
    }).print(localDateTime));
    assertEquals(DateTimeFormat.fullDate().print(localDateTime), JodaTimeHelper.getDateTimeFormatter(new DefaultDateFormatSupplier() {

        @Override
        public String get() {
            return "yyyy";
        }
    }, DateTimeFormat.fullDate()).print(localDateTime));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) DefaultDateFormatSupplier(org.simpleflatmapper.util.date.DefaultDateFormatSupplier) Test(org.junit.Test)

Aggregations

DefaultDateFormatSupplier (org.simpleflatmapper.util.date.DefaultDateFormatSupplier)8 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Test (org.junit.Test)3 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ArrayList (java.util.ArrayList)2 DateTimeZone (org.joda.time.DateTimeZone)2 LocalDateTime (org.joda.time.LocalDateTime)2 Date (java.util.Date)1 Converter (org.simpleflatmapper.converter.Converter)1 ConvertingScore (org.simpleflatmapper.converter.ConvertingScore)1 ConvertingTypes (org.simpleflatmapper.converter.ConvertingTypes)1 ToStringConverter (org.simpleflatmapper.converter.ToStringConverter)1 DateFormatSupplier (org.simpleflatmapper.util.date.DateFormatSupplier)1