package com.fp.dto.json;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

public class DateValueProcessor implements JsonValueProcessor {
    public static final String DATE_TRANSPORT = "yyyy-MM-dd";

    public static final String TIMESTAMP_TRANSPORT = "yyyy-MM-dd HH:mm:ss";

    @Override
    public Object processArrayValue(Object value, JsonConfig jsonConfig) {
        String data = "";
        if (value instanceof Date) {
            SimpleDateFormat sdf = new SimpleDateFormat(DateValueProcessor.DATE_TRANSPORT);
            data = sdf.format((java.util.Date) value);
        } else if (value instanceof Timestamp) {
            SimpleDateFormat sdf = new SimpleDateFormat(DateValueProcessor.TIMESTAMP_TRANSPORT);
            data = sdf.format((java.util.Date) value);
        }
        return data;
    }

    @Override
    public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
        String data = "";
        if (value instanceof Date) {
            SimpleDateFormat sdf = new SimpleDateFormat(DateValueProcessor.DATE_TRANSPORT);
            data = sdf.format((Date) value);
        } else if (value instanceof Timestamp) {
            SimpleDateFormat sdf = new SimpleDateFormat(DateValueProcessor.TIMESTAMP_TRANSPORT);
            data = sdf.format((Timestamp) value);
        }
        return data;
    }

}
