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

com.tecacet.util.conversion.LocalTimeConverter Maven / Gradle / Ivy

Go to download

JFlat's purpose is to convert flat files to Java Beans and vice versa. Some supported formats are CSV, fixed-width, arbitrary delimiters, and excel files. There are also tools to generate Java Beans to/from JDBC and Swing tables. JFlat is highly extensible and can be adopted to support additional formats.

The newest version!
package com.tecacet.util.conversion;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.beanutils.ConversionException;
import org.joda.time.LocalTime;

public class LocalTimeConverter implements DataConverter {

	private final DateFormat format;

	public LocalTimeConverter(final String format) {
		super();
		this.format = new SimpleDateFormat(format);
	}

	@Override
	public LocalTime convert(String from) {
		if (isEmpty(from)) {
			return null;
		}
		Date date;
		try {
			date = format.parse(from.trim());
		} catch (ParseException e) {
			throw new ConversionException(e);
		}
		return new LocalTime(date);
	}

	private boolean isEmpty(String s) {
		return s == null || s.trim().equals("");
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy