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

nl.vpro.rs.converters.DateParamConverter Maven / Gradle / Ivy

package nl.vpro.rs.converters;

import java.util.Calendar;
import java.util.Date;

import jakarta.ws.rs.ext.ParamConverter;
import jakarta.xml.bind.DatatypeConverter;


/**
 * @author Michiel Meeuwissen
 * @since 0.23
 */

public class DateParamConverter implements ParamConverter {

    static DateParamConverter INSTANCE = new DateParamConverter();

    @Override
    public Date fromString(String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return DatatypeConverter.parseDateTime(value).getTime();


    }

    @Override
    public String toString(Date value) {
        if (value == null) {
           return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(value);
        return DatatypeConverter.printDateTime(cal);

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy