package com.tmerclub.cloud.search.canal.support.parser.converter;


import java.sql.JDBCType;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author throwable
 * @version v1
 * @description
 * @since 2020/9/22 0:41
 */
public class TimestampCanalFieldConverter1 extends BaseCanalFieldConverter<Date> {

    public static final BaseCanalFieldConverter<Date> X = new TimestampCanalFieldConverter1();

    private TimestampCanalFieldConverter1() {
        super(JDBCType.TIMESTAMP, Date.class);
    }

    @Override
    protected Date convertInternal(String source) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return format.parse(source);
        } catch (ParseException e) {
            throw new IllegalArgumentException(String.format("转换日期时间类型java.util.Date失败,原始字符串:%s", source), e);
        }
    }
}
