All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.map.column.joda.JodaHelper Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 1.10.3
Show newest version
package org.sfm.map.column.joda;

import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.sfm.map.ColumnDefinition;
import org.sfm.map.column.DateFormatProperty;
import org.sfm.map.column.TimeZoneProperty;

public class JodaHelper {

    public static DateTimeFormatter getDateTimeFormatter(ColumnDefinition columnDefinition) {
        DateTimeFormatter dtf;

        if (columnDefinition.has(JodaDateTimeFormatterProperty.class)) {
            dtf = columnDefinition.lookFor(JodaDateTimeFormatterProperty.class).getFormatter();
        } else if (columnDefinition.has(DateFormatProperty.class)) {
            dtf = DateTimeFormat.forPattern(columnDefinition.lookFor(DateFormatProperty.class).getPattern());
        } else {
            throw new IllegalArgumentException("No date format pattern specified");
        }

        if (columnDefinition.has(JodaDateTimeZoneProperty.class)) {
            dtf = dtf.withZone(columnDefinition.lookFor(JodaDateTimeZoneProperty.class).getZone());
        } else if (columnDefinition.has(TimeZoneProperty.class)) {
            dtf = dtf.withZone(DateTimeZone.forTimeZone(columnDefinition.lookFor(TimeZoneProperty.class).getTimeZone()));
        } else {
            dtf = dtf.withZone(DateTimeZone.getDefault());
        }

        return dtf;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy