All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.xishan.oftenporter.demo.util.DateParser Maven / Gradle / Ivy

package cn.xishan.oftenporter.demo.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import cn.xishan.oftenporter.porter.core.annotation.MayNull;
import cn.xishan.oftenporter.porter.core.annotation.NotNull;
import cn.xishan.oftenporter.porter.core.advanced.ITypeParser;
import cn.xishan.oftenporter.porter.core.base.OftenObject;

public class DateParser extends ITypeParser.Adapter {


    public DateParser() {

    }

    @Override
    public ParseResult parse(OftenObject oftenObject,@NotNull String name, @NotNull Object value,@MayNull Object dealt) {
        ParseResult result;
        try {
            Object v;
            if (value instanceof Date) {
                v = value;
            } else {
                SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                Date date = format.parse(String.valueOf(value));
                v = date;
            }
            result = new ParseResult(v);
        } catch (Exception e) {
            result = ParseResult
                    .failed(getClass().getSimpleName() + ":" + e.getMessage());
        }

        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy