com.github.fedy2.weather.binding.adapter.DateAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yahoo-weather-java-api Show documentation
Show all versions of yahoo-weather-java-api Show documentation
A Java library for the yahoo weather RSS feed service
/**
*
*/
package com.github.fedy2.weather.binding.adapter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author "Federico De Faveri [email protected]"
*
*/
public class DateAdapter extends XmlAdapter {
protected Logger logger = LoggerFactory.getLogger(DateAdapter.class);
protected SimpleDateFormat dateFormat = new SimpleDateFormat("d MMM yyyy");
/**
* {@inheritDoc}
*/
@Override
public String marshal(Date v) throws Exception {
return dateFormat.format(v);
}
/**
* {@inheritDoc}
*/
@Override
public Date unmarshal(String v) throws Exception {
try {
return dateFormat.parse(v);
} catch(Exception e) {
logger.warn("Unknow date format \"{}\"",v);
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy