com.github.debugthug.converters.DateConverterTest Maven / Gradle / Ivy
package com.github.debugthug.converters;
import java.text.ParseException;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
public class DateConverterTest extends AbstractSingleValueConverter {
@Override
@SuppressWarnings("rawtypes")
public boolean canConvert(Class cls) {
return cls.equals(Date.class);
}
@Override
public Object fromString(String str) {
Date date = null;
try {
if (StringUtils.contains(str, "Hrs.")) {
str = StringUtils.trim(str.replace("Hrs.", ""));
}
date = DateUtils.parseDate(str, new String[] { "yyyyMMdd", "dd MMM yyyy HH:mm", "" });
}
catch (ParseException e) {
e.printStackTrace();
}
return date;
}
}