/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.converter;

import java.util.Date;

import org.apache.commons.beanutils.Converter;

import com.crunii.micro.common.utils.DateUtil;

/**
 * @author 田平 create 2018年10月19日下午1:02:31
 */
public class DateConverter implements Converter {

	private static DateConverter converter = new DateConverter();

	private DateConverter() {

	}

	public static DateConverter getDateConverter() {
		return converter;
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T convert(Class<T> type, Object value) {
		if (value != null) {
			if (value instanceof Date) {
				return (T) value;
			} else {
				return (T) DateUtil.parse(value.toString());
			}
		} else {
			return null;
		}
	}

}
