package com.foreverwin.mesnac.common.export;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

public class DateConvert implements ColumnConvert {
    public static String[] patterns = {"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy-MM-dd'T'HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyyMMdd"};

    @Override
    public String convert(JSONObject row, String column, String value) {
        if (StrUtil.isBlank(value)) return "";
        //--------------------------------------------------------------------------------------------------------
        try {
            return DateFormatUtils.format(DateUtils.parseDate(value, patterns), "yyyy-MM-dd HH:mm:ss");
        } catch (Exception e) {
            ;
        }//try
        //--------------------------------------------------------------------------------------------------------
        return value;
    }
}
