org.simpleflatmapper.converter.impl.time.JavaTimeConverterFactoryProducer Maven / Gradle / Ivy
package org.simpleflatmapper.converter.impl.time;
import org.simpleflatmapper.converter.AbstractContextualConverterFactory;
import org.simpleflatmapper.converter.AbstractConverterFactory;
import org.simpleflatmapper.converter.AbstractContextualConverterFactoryProducer;
import org.simpleflatmapper.converter.ContextFactoryBuilder;
import org.simpleflatmapper.converter.ContextualConverter;
import org.simpleflatmapper.converter.ContextualConverterFactory;
import org.simpleflatmapper.converter.ConvertingTypes;
import org.simpleflatmapper.converter.ToStringConverter;
import org.simpleflatmapper.util.Consumer;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.Date;
public class JavaTimeConverterFactoryProducer extends AbstractContextualConverterFactoryProducer {
@Override
public void produce(Consumer super ContextualConverterFactory, ?>> consumer) {
constantConverter(consumer, Instant.class, Date.class, new JavaInstantTojuDateConverter());
factoryConverter(consumer, new AbstractContextualConverterFactory(LocalDateTime.class, Date.class) {
@Override
public ContextualConverter super LocalDateTime, ? extends Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new JavaLocalDateTimeTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(LocalDate.class, Date.class) {
@Override
public ContextualConverter super LocalDate, ? extends Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new JavaLocalDateTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(LocalTime.class, Date.class) {
@Override
public ContextualConverter super LocalTime, ? extends Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new JavaLocalTimeTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
constantConverter(consumer, ZonedDateTime.class, Date.class, new JavaZonedDateTimeTojuDateConverter());
constantConverter(consumer, OffsetDateTime.class, Date.class, new JavaOffsetDateTimeTojuDateConverter());
constantConverter(consumer, OffsetTime.class, Date.class, new JavaOffsetTimeTojuDateConverter());
factoryConverter(consumer, new AbstractContextualConverterFactory(YearMonth.class, Date.class) {
@Override
public ContextualConverter super YearMonth, ? extends Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new JavaYearMonthTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Year.class, Date.class) {
@Override
public ContextualConverter super Year, ? extends Date> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new JavaYearTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
constantConverter(consumer, Date.class, Instant.class, new DateToJavaInstantConverter());
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, LocalDateTime.class) {
@Override
public ContextualConverter super Date, ? extends LocalDateTime> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaLocalDateTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, LocalDate.class) {
@Override
public ContextualConverter super Date, ? extends LocalDate> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaLocalDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, LocalTime.class) {
@Override
public ContextualConverter super Date, ? extends LocalTime> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaLocalTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, ZonedDateTime.class) {
@Override
public ContextualConverter super Date, ? extends ZonedDateTime> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaZonedDateTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, OffsetDateTime.class) {
@Override
public ContextualConverter super Date, ? extends OffsetDateTime> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaOffsetDateTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, OffsetTime.class) {
@Override
public ContextualConverter super Date, ? extends OffsetTime> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaOffsetTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, YearMonth.class) {
@Override
public ContextualConverter super Date, ? extends YearMonth> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaYearMonthConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory(Date.class, Year.class) {
@Override
public ContextualConverter super Date, ? extends Year> newConverter(ConvertingTypes targetedTypes, ContextFactoryBuilder contextFactoryBuilder, Object... params) {
return new DateToJavaYearConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractContextualConverterFactory
© 2015 - 2025 Weber Informatics LLC | Privacy Policy