com.feilong.lib.xstream.converters.extended.ISO8601DateConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of feilong Show documentation
Show all versions of feilong Show documentation
feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.
/*
* Copyright (C) 2004, 2005 Joe Walnes.
* Copyright (C) 2006, 2007, 2017, 2018 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 22. November 2004 by Mauro Talevi
*/
package com.feilong.lib.xstream.converters.extended;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import com.feilong.lib.xstream.converters.basic.AbstractSingleValueConverter;
/**
* A DateConverter conforming to the ISO8601 standard.
* http://www.iso.ch/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=26780
*
* @author Mauro Talevi
* @author Jörg Schaible
*/
public class ISO8601DateConverter extends AbstractSingleValueConverter{
private final ISO8601GregorianCalendarConverter converter = new ISO8601GregorianCalendarConverter();
@Override
public boolean canConvert(Class type){
return type == Date.class && converter.canConvert(GregorianCalendar.class);
}
@Override
public Object fromString(String str){
return ((Calendar) converter.fromString(str)).getTime();
}
@Override
public String toString(Object obj){
final Calendar calendar = Calendar.getInstance();
calendar.setTime((Date) obj);
return converter.toString(calendar);
}
}