package de.timroes.axmlrpc.serializer;

import de.timroes.axmlrpc.XMLRPCException;
import de.timroes.axmlrpc.XMLUtil;
import de.timroes.axmlrpc.xmlcreator.XmlElement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.w3c.dom.Element;

/**
 *
 * @author timroes
 */
public class DateTimeSerializer implements Serializer {

	private static final String DATETIME_FORMAT = "yyyyMMdd'T'HH:mm:ss";
	private static final SimpleDateFormat DATE_FORMATER = new SimpleDateFormat(DATETIME_FORMAT);

	public Object deserialize(Element content) throws XMLRPCException {
		try {
			return DATE_FORMATER.parse(XMLUtil.getOnlyTextContent(content.getChildNodes()));
		} catch (ParseException ex) {
			throw new XMLRPCException("Unable to parse given date.", ex);
		}
	}

	public XmlElement serialize(Object object) {
		return XMLUtil.makeXmlTag(SerializerHandler.TYPE_DATETIME,
				DATE_FORMATER.format(object));
	}

}

@@ -33,16 +33,145 @@
 lizer;%0A%0A
+import java.text.SimpleDateFormat;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport org.w3c.dom.Element;%0A%0A
 import d
@@ -292,104 +292,8 @@
 ent;
-%0Aimport java.text.ParseException;%0Aimport java.text.SimpleDateFormat;%0Aimport org.w3c.dom.Element;
 %0A%0A/*
@@ -541,16 +541,275 @@
 ORMAT);%0A
+%09private static final Pattern PATTERN_WITHOUT_COLON = Pattern.compile(%22(%5C%5Cd%7B4%7D-%5C%5Cd%7B2%7D-%5C%5Cd%7B2%7DT%5C%5Cd%7B2%7D:%5C%5Cd%7B2%7D:%5C%5Cd%7B2%7D%5C%5C+%5C%5Cd%7B2%7D)(%5C%5Cd%7B2%7D)%22);%0A%09private static final Pattern PATTERN_LEGACY = Pattern.compile(%22(%5C%5Cd%7B4%7D)(%5C%5Cd%7B2%7D)(%5C%5Cd%7B2%7DT%5C%5Cd%7B2%7D:%5C%5Cd%7B2%7D:%5C%5Cd%7B2%7D)%22);%0A%0A%09@Override
 %0A%09public
@@ -885,34 +885,43 @@
 %0A%09%09%09
-return DATE_FORMATER.parse
+String value = formatStringIfNeeded
 (XML
@@ -971,16 +971,91 @@
 es()));%0A
+%09%09%09return javax.xml.bind.DatatypeConverter.parseDateTime(value).getTime();%0A
 %09%09%7D catc
@@ -1061,13 +1061,8 @@
 ch (
-Parse
 Exce
@@ -1146,16 +1146,498 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09private static String formatStringIfNeeded(String dateStr)%7B%0A%09%09Matcher matcherWithoutColon = PATTERN_WITHOUT_COLON.matcher(dateStr);%0A%09%09if ( matcherWithoutColon.matches() )%7B%0A%09%09%09return matcherWithoutColon.group(1) + %22:%22 + matcherWithoutColon.group(2);%0A%09%09%7D%0A%0A%09%09Matcher matcherLegacy = PATTERN_LEGACY.matcher(dateStr);%0A%09%09if ( matcherLegacy.matches() )%7B%0A%09%09%09return matcherLegacy.group(1) + %22-%22 + matcherLegacy.group(2) + %22-%22 + matcherLegacy.group(3);%0A%09%09%7D%0A%0A%09%09return dateStr;%0A%09%7D%0A%0A%09@Override%0A
 %09public 

Improves date parsing