package cn.superdesk.uniorder.common.numerical;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;

import java.util.Date;


@Deprecated
@Slf4j
public class AnDateConverter implements Converter<String, Date> {


	@Override
	public Date convert(String source) {

		Date date = null;

		try {
			if (StringUtils.isEmpty(source)) {
				return null;
			}

			source = source.trim();

			if (source.length() < 12) {
				date = AnDateHelper.parseToDate(source, AnDateHelper.CURRENT_DATE);
			} else {
				date = AnDateHelper.parseToDate(source, AnDateHelper.DATE_TIME_STRING);
			}

			return date;

		} catch (Exception e) {
			log.error("spring mvc 自动类型字符串转日期类型失败！");
		}

		return date;
	}
}
